! @brief updates a JSON object from another object, overwriting existing keys Inserts all values from JSON object @a j and overwrites existing keys. @param[in] j JSON object to read values from @throw type_error.312 if called on JSON values other than objects; example: `"cannot use update() with string"` @complexity O(N*log(size() + N)), where N is the number of elemen
| 22338 | @since version 3.0.0 |
| 22339 | */ |
| 22340 | void update(const_reference j) |
| 22341 | { |
| 22342 | // implicitly convert null value to an empty object |
| 22343 | if (is_null()) |
| 22344 | { |
| 22345 | m_type = value_t::object; |
| 22346 | m_value.object = create<object_t>(); |
| 22347 | assert_invariant(); |
| 22348 | } |
| 22349 | |
| 22350 | if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| 22351 | { |
| 22352 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()))); |
| 22353 | } |
| 22354 | if (JSON_HEDLEY_UNLIKELY(!j.is_object())) |
| 22355 | { |
| 22356 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()))); |
| 22357 | } |
| 22358 | |
| 22359 | for (auto it = j.cbegin(); it != j.cend(); ++it) |
| 22360 | { |
| 22361 | m_value.object->operator[](it.key()) = it.value(); |
| 22362 | } |
| 22363 | } |
| 22364 | |
| 22365 | /*! |
| 22366 | @brief updates a JSON object from another object, overwriting existing keys |
no test coverage detected