@brief access specified array element with bounds checking @sa https://json.nlohmann.me/api/basic_json/at/
| 21146 | /// @brief access specified array element with bounds checking |
| 21147 | /// @sa https://json.nlohmann.me/api/basic_json/at/ |
| 21148 | reference at(size_type idx) |
| 21149 | { |
| 21150 | // at only works for arrays |
| 21151 | if (JSON_HEDLEY_LIKELY(is_array())) |
| 21152 | { |
| 21153 | JSON_TRY |
| 21154 | { |
| 21155 | return set_parent(m_value.array->at(idx)); |
| 21156 | } |
| 21157 | JSON_CATCH (std::out_of_range&) |
| 21158 | { |
| 21159 | // create better exception explanation |
| 21160 | JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); |
| 21161 | } |
| 21162 | } |
| 21163 | else |
| 21164 | { |
| 21165 | JSON_THROW(type_error::create(304, detail::concat("cannot use at() with ", type_name()), this)); |