MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / at

Function at

Source/Utils/json.hpp:19792–19806  ·  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 inde

Source from the content-addressed store, hash-verified

19790 can be thrown.,at__size_type}
19791 */
19792 reference at(size_type idx)
19793 {
19794 // at only works for arrays
19795 if (JSON_HEDLEY_LIKELY(is_array()))
19796 {
19797 JSON_TRY
19798 {
19799 return m_value.array->at(idx);
19800 }
19801 JSON_CATCH(std::out_of_range&)
19802 {
19803 // create better exception explanation
19804 JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
19805 }
19806 }
19807 else
19808 {
19809 JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name())));

Callers 1

ordered_mapClass · 0.85

Calls 2

is_arrayFunction · 0.85
is_objectFunction · 0.85

Tested by

no test coverage detected