MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / at

Function at

native/thirdpart/json/json.hpp:17519–17533  ·  view source on GitHub ↗

! @brief access specified array element with bounds checking Returns a reference to the element at specified location @a idx, with bounds checking. @param[in] idx index of the element to access @return reference to the element at index @a idx @throw type_error.304 if the JSON value is not an array; in this case, calling `at` with an index makes no sense. See exampl

Source from the content-addressed store, hash-verified

17517 can be thrown.,at__size_type}
17518 */
17519 reference at(size_type idx)
17520 {
17521 // at only works for arrays
17522 if (JSON_HEDLEY_LIKELY(is_array()))
17523 {
17524 JSON_TRY
17525 {
17526 return m_value.array->at(idx);
17527 }
17528 JSON_CATCH (std::out_of_range&)
17529 {
17530 // create better exception explanation
17531 JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
17532 }
17533 }
17534 else
17535 {
17536 JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name())));

Callers

nothing calls this directly

Calls 2

is_arrayFunction · 0.85
is_objectFunction · 0.85

Tested by

no test coverage detected