TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ push_back() [3/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back ( const typename object_t::value_type &  val)
inline

add an object to an object

Inserts the given element val to the JSON object. If the function is called on a JSON null value, an empty object is created before inserting val.

Parameters
[in]valthe value to add to the JSON object
Exceptions
type_error.308when called on a type other than JSON object or null; example: "cannot use push_back() with number"

@complexity Logarithmic in the size of the container, O(log(size())).

@liveexample{The example shows how push_back() and += can be used to add elements to a JSON object. Note how the null value was silently converted to a JSON object.,push_back__object_t__value}

Since
version 1.0.0

Definition at line 23237 of file json.hpp.

23238 {
23239 // push_back only works for null objects or objects
23240 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
23241 {
23242 JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
23243 }
23244
23245 // transform null object into an object
23246 if (is_null())
23247 {
23248 m_type = value_t::object;
23251 }
23252
23253 // add element to object
23254 auto res = m_value.object->insert(val);
23255 set_parent(res.first->second);
23256 }
void assert_invariant(bool check_parents=true) const noexcept
checks the class invariants
Definition: json.hpp:18935
constexpr bool is_object() const noexcept
return whether value is an object
Definition: json.hpp:20410
json_value m_value
the value of the current element
Definition: json.hpp:24928
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition: json.hpp:24883
constexpr bool is_null() const noexcept
return whether value is null
Definition: json.hpp:20251
@ object
object (unordered set of name/value pairs)