MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / push_back

Function push_back

3rd/nlohmann_json/single_include/nlohmann/json.hpp:22952–22973  ·  view source on GitHub ↗

! @brief add an object to an array Appends the given element @a val to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending @a val. @param[in] val the value to add to the JSON array @throw type_error.308 when called on a type other than JSON array or null; example: `"cannot use push_back() with number"`

Source from the content-addressed store, hash-verified

22950 @since version 1.0.0
22951 */
22952 void push_back(basic_json&& val)
22953 {
22954 // push_back only works for null objects or arrays
22955 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22956 {
22957 JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
22958 }
22959
22960 // transform null object into an array
22961 if (is_null())
22962 {
22963 m_type = value_t::array;
22964 m_value = value_t::array;
22965 assert_invariant();
22966 }
22967
22968 // add element to array (move semantics)
22969 const auto old_capacity = m_value.array->capacity();
22970 m_value.array->push_back(std::move(val));
22971 set_parent(m_value.array->back(), old_capacity);
22972 // if val is moved from, basic_json move constructor marks it null so we do not call the destructor
22973 }
22974
22975 /*!
22976 @brief add an object to an array

Callers 3

json_pointerClass · 0.70
insertMethod · 0.70
operator+=Function · 0.70

Calls 14

stringFunction · 0.85
is_nullFunction · 0.70
is_arrayFunction · 0.70
createFunction · 0.70
type_nameFunction · 0.70
set_parentFunction · 0.70
is_objectFunction · 0.70
basic_jsonFunction · 0.70
capacityMethod · 0.45
push_backMethod · 0.45
insertMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected