From d1e13d51281b6caf008869845792d77f72175a11 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 2 Aug 2017 22:12:41 +0200 Subject: [PATCH] :tada: first draft for #661 --- src/json.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/json.hpp b/src/json.hpp index c22cce4f9..5253a613b 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -12066,6 +12066,31 @@ class basic_json m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator); } + void update(const_reference j) + { + // implicitly convert null value to an empty object + if (is_null()) + { + m_type = value_t::object; + m_value.object = create(); + assert_invariant(); + } + + if (JSON_UNLIKELY(not is_object())) + { + JSON_THROW(type_error::create(305, "cannot use merge with " + type_name())); + } + if (JSON_UNLIKELY(not j.is_object())) + { + JSON_THROW(type_error::create(305, "cannot use merge with " + j.type_name())); + } + + for (auto it = j.begin(); it != j.end(); ++it) + { + m_value.object->emplace(it.key(), it.value()); + } + } + /*! @brief exchanges the values