! @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
| 17507 | @since version 3.0.0 |
| 17508 | */ |
| 17509 | void update(const_reference j) |
| 17510 | { |
| 17511 | // implicitly convert null value to an empty object |
| 17512 | if (is_null()) |
| 17513 | { |
| 17514 | m_type = value_t::object; |
| 17515 | m_value.object = create<object_t>(); |
| 17516 | assert_invariant(); |
| 17517 | } |
| 17518 | |
| 17519 | if (JSON_UNLIKELY(not is_object())) |
| 17520 | { |
| 17521 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()))); |
| 17522 | } |
| 17523 | if (JSON_UNLIKELY(not j.is_object())) |
| 17524 | { |
| 17525 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()))); |
| 17526 | } |
| 17527 | |
| 17528 | for (auto it = j.cbegin(); it != j.cend(); ++it) |
| 17529 | { |
| 17530 | m_value.object->operator[](it.key()) = it.value(); |
| 17531 | } |
| 17532 | } |
| 17533 | |
| 17534 | /*! |
| 17535 | @brief updates a JSON object from another object, overwriting existing keys |
nothing calls this directly
no test coverage detected