TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ push_back() [4/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 ( initializer_list_t  init)
inline

add an object to an object

This function allows to use push_back with an initializer list. In case

  1. the current value is an object,
  2. the initializer list init contains only two elements, and
  3. the first element of init is a string,

init is converted into an object element and added using push_back(const typename object_t::value_type&). Otherwise, init is converted to a JSON value and added using push_back(basic_json&&).

Parameters
[in]initan initializer list

@complexity Linear in the size of the initializer list init.

Note
This function is required to resolve an ambiguous overload error, because pairs like {"key", "value"} can be both interpreted as object_t::value_type or std::initializer_list<basic_json>, see https://github.com/nlohmann/json/issues/235 for more information.

@liveexample{The example shows how initializer lists are treated as objects when possible.,push_back__initializer_list}

Definition at line 23293 of file json.hpp.

23294 {
23295 if (is_object() && init.size() == 2 && (*init.begin())->is_string())
23296 {
23297 basic_json &&key = init.begin()->moved_or_copied();
23298 push_back(typename object_t::value_type(
23299 std::move(key.get_ref<string_t &>()), (init.begin() + 1)->moved_or_copied()));
23300 }
23301
23302 else
23303 {
23304 push_back(basic_json(init));
23305 }
23306 }
basic_json(const value_t v)
create an empty value with a given type
Definition: json.hpp:19164
StringType string_t
a type for a string
Definition: json.hpp:18292
constexpr bool is_object() const noexcept
return whether value is an object
Definition: json.hpp:20410
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:23148
@ key
the parser read a key of a value in an object