MCPcopy Create free account
hub / github.com/PeterFWS/Structure-PLP-SLAM / operator[]

Function operator[]

3rd/json/include/nlohmann/json.hpp:15875–15900  ·  view source on GitHub ↗

! @brief access specified array element Returns a reference to the element at specified location @a idx. @note If @a idx is beyond the range of the array (i.e., `idx >= size()`), then the array is silently filled up with `null` values to make `idx` a valid reference to the last stored element. @param[in] idx index of the element to access @return reference to the e

Source from the content-addressed store, hash-verified

15873 @since version 1.0.0
15874 */
15875 reference operator[](size_type idx)
15876 {
15877 // implicitly convert null value to an empty array
15878 if (is_null())
15879 {
15880 m_type = value_t::array;
15881 m_value.array = create<array_t>();
15882 assert_invariant();
15883 }
15884
15885 // operator[] only works for arrays
15886 if (JSON_LIKELY(is_array()))
15887 {
15888 // fill up array with null values if given idx is outside range
15889 if (idx >= m_value.array->size())
15890 {
15891 m_value.array->insert(m_value.array->end(),
15892 idx - m_value.array->size() + 1,
15893 basic_json());
15894 }
15895
15896 return m_value.array->operator[](idx);
15897 }
15898
15899 JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name())));
15900 }
15901
15902 /*!
15903 @brief access specified array element

Callers

nothing calls this directly

Calls 12

is_nullFunction · 0.85
assert_invariantFunction · 0.85
is_arrayFunction · 0.85
type_nameFunction · 0.85
is_objectFunction · 0.85
findMethod · 0.80
basic_jsonFunction · 0.70
createFunction · 0.70
sizeMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
operator[]Method · 0.45

Tested by

no test coverage detected