! @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
| 19874 | can be thrown.,at__size_type} |
| 19875 | */ |
| 19876 | reference at(size_type idx) |
| 19877 | { |
| 19878 | // at only works for arrays |
| 19879 | if (JSON_HEDLEY_LIKELY(is_array())) |
| 19880 | { |
| 19881 | JSON_TRY |
| 19882 | { |
| 19883 | return m_value.array->at(idx); |
| 19884 | } |
| 19885 | JSON_CATCH (std::out_of_range&) |
| 19886 | { |
| 19887 | // create better exception explanation |
| 19888 | JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range")); |
| 19889 | } |
| 19890 | } |
| 19891 | else |
| 19892 | { |
| 19893 | JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()))); |
no test coverage detected