! @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
| 22254 | @since version 3.0.0 |
| 22255 | */ |
| 22256 | void update(const_reference j) |
| 22257 | { |
| 22258 | // implicitly convert null value to an empty object |
| 22259 | if (is_null()) |
| 22260 | { |
| 22261 | m_type = value_t::object; |
| 22262 | m_value.object = create<object_t>(); |
| 22263 | assert_invariant(); |
| 22264 | } |
| 22265 | |
| 22266 | if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| 22267 | { |
| 22268 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()))); |
| 22269 | } |
| 22270 | if (JSON_HEDLEY_UNLIKELY(!j.is_object())) |
| 22271 | { |
| 22272 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()))); |
| 22273 | } |
| 22274 | |
| 22275 | for (auto it = j.cbegin(); it != j.cend(); ++it) |
| 22276 | { |
| 22277 | m_value.object->operator[](it.key()) = it.value(); |
| 22278 | } |
| 22279 | } |
| 22280 | |
| 22281 | /*! |
| 22282 | @brief updates a JSON object from another object, overwriting existing keys |
nothing calls this directly
no test coverage detected