TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ insert() [1/6]

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 >::insert ( const_iterator  first,
const_iterator  last 
)
inline

inserts elements

Inserts elements from range [first, last).

Parameters
[in]firstbegin of the range of elements to insert
[in]lastend of the range of elements to insert
Exceptions
type_error.309if called on JSON values other than objects; example: "cannot use insert() with string"
invalid_iterator.202if iterator first or last does does not point to an object; example: "iterators first and last must point to objects"
invalid_iterator.210if first and last do not belong to the same JSON value; example: "iterators do not fit"

@complexity Logarithmic: O(N*log(size() + N)), where N is the number of elements to insert.

@liveexample{The example shows how insert() is used.,insert__range_object}

Since
version 3.0.0

Definition at line 23651 of file json.hpp.

23652 {
23653 // insert only works for objects
23654 if (JSON_HEDLEY_UNLIKELY(!is_object()))
23655 {
23656 JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
23657 }
23658
23659 // check if range iterators belong to the same JSON object
23660 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23661 {
23662 JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
23663 }
23664
23665 // passed iterators must belong to objects
23666 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
23667 {
23668 JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this));
23669 }
23670
23671 m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
23672 }
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