@brief access specified array element with bounds checking @sa https://json.nlohmann.me/api/basic_json/at/
| 21102 | /// @brief access specified array element with bounds checking |
| 21103 | /// @sa https://json.nlohmann.me/api/basic_json/at/ |
| 21104 | reference at(size_type idx) |
| 21105 | { |
| 21106 | // at only works for arrays |
| 21107 | if (JSON_HEDLEY_LIKELY(is_array())) |
| 21108 | { |
| 21109 | JSON_TRY |
| 21110 | { |
| 21111 | return set_parent(m_value.array->at(idx)); |
| 21112 | } |
| 21113 | JSON_CATCH (std::out_of_range&) |
| 21114 | { |
| 21115 | // create better exception explanation |
| 21116 | JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); |
| 21117 | } |
| 21118 | } |
| 21119 | else |
| 21120 | { |
| 21121 | JSON_THROW(type_error::create(304, detail::concat("cannot use at() with ", type_name()), this)); |