MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/PositionBasedDynamics / at

Method at

extern/json/json.hpp:3151–3170  ·  view source on GitHub ↗

! @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 std::domain_error if the JSON value is not an array; example: `"cannot use at() with string"` @throw std::out_of_

Source from the content-addressed store, hash-verified

3149 @since version 1.0.0
3150 */
3151 reference at(size_type idx)
3152 {
3153 // at only works for arrays
3154 if (is_array())
3155 {
3156 try
3157 {
3158 return m_value.array->at(idx);
3159 }
3160 catch (std::out_of_range&)
3161 {
3162 // create better exception explanation
3163 throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
3164 }
3165 }
3166 else
3167 {
3168 throw std::domain_error("cannot use at() with " + type_name());
3169 }
3170 }
3171
3172 /*!
3173 @brief access specified array element with bounds checking

Callers 2

get_checkedMethod · 0.45
patchMethod · 0.45

Calls 1

get_checkedMethod · 0.80

Tested by

no test coverage detected