MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / at

Function at

3rd/nlohmann_json/single_include/nlohmann/json.hpp:20987–21001  ·  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

20985 can be thrown.,at__size_type}
20986 */
20987 reference at(size_type idx)
20988 {
20989 // at only works for arrays
20990 if (JSON_HEDLEY_LIKELY(is_array()))
20991 {
20992 JSON_TRY
20993 {
20994 return set_parent(m_value.array->at(idx));
20995 }
20996 JSON_CATCH (std::out_of_range&)
20997 {
20998 // create better exception explanation
20999 JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
21000 }
21001 }
21002 else
21003 {
21004 JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));

Callers 1

ordered_mapClass · 0.70

Calls 3

is_arrayFunction · 0.70
set_parentFunction · 0.70
is_objectFunction · 0.70

Tested by

no test coverage detected