! @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
| 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)); |
no test coverage detected