! @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
| 3484 | can be thrown.,at__size_type} |
| 3485 | */ |
| 3486 | reference at(size_type idx) |
| 3487 | { |
| 3488 | // at only works for arrays |
| 3489 | if (JSON_HEDLEY_LIKELY(is_array())) |
| 3490 | { |
| 3491 | JSON_TRY |
| 3492 | { |
| 3493 | return set_parent(m_value.array->at(idx)); |
| 3494 | } |
| 3495 | JSON_CATCH (std::out_of_range&) |
| 3496 | { |
| 3497 | // create better exception explanation |
| 3498 | JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this)); |
| 3499 | } |
| 3500 | } |
| 3501 | else |
| 3502 | { |
| 3503 | JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this)); |
no test coverage detected