TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ update() [1/2]

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

updates a JSON object from another object, overwriting existing keys

Inserts all values from from range [first, last) and overwrites existing keys.

Parameters
[in]firstbegin of the range of elements to insert
[in]lastend of the range of elements to insert
Exceptions
type_error.312if called on JSON values other than objects; example: "cannot use update() 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 O(N*log(size() + N)), where N is the number of elements to insert.

@liveexample{The example shows how update() is used__range.,update}

See also
https://docs.python.org/3.6/library/stdtypes.html#dict.update
Since
version 3.0.0

Definition at line 23748 of file json.hpp.

23749 {
23750 // implicitly convert null value to an empty object
23751 if (is_null())
23752 {
23753 m_type = value_t::object;
23754 m_value.object = create<object_t>();
23756 }
23757
23758 if (JSON_HEDLEY_UNLIKELY(!is_object()))
23759 {
23760 JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this));
23761 }
23762
23763 // check if range iterators belong to the same JSON object
23764 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23765 {
23766 JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
23767 }
23768
23769 // passed iterators must belong to objects
23770 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
23771 || !last.m_object->is_object()))
23772 {
23773 JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this));
23774 }
23775
23776 for (auto it = first; it != last; ++it)
23777 {
23778 m_value.object->operator[](it.key()) = it.value();
23779#if JSON_DIAGNOSTICS
23780 m_value.object->operator[](it.key()).m_parent = this;
23781#endif
23782 }
23783 }
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)