| 22377 | /// @sa https://json.nlohmann.me/api/basic_json/emplace_back/ |
| 22378 | template<class... Args> |
| 22379 | reference emplace_back(Args&& ... args) |
| 22380 | { |
| 22381 | // emplace_back only works for null objects or arrays |
| 22382 | if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) |
| 22383 | { |
| 22384 | JSON_THROW(type_error::create(311, detail::concat("cannot use emplace_back() with ", type_name()), this)); |
| 22385 | } |
| 22386 | |
| 22387 | // transform null object into an array |
| 22388 | if (is_null()) |
| 22389 | { |
| 22390 | m_type = value_t::array; |
| 22391 | m_value = value_t::array; |
| 22392 | assert_invariant(); |
| 22393 | } |
| 22394 | |
| 22395 | // add element to array (perfect forwarding) |
| 22396 | const auto old_capacity = m_value.array->capacity(); |
| 22397 | m_value.array->emplace_back(std::forward<Args>(args)...); |
| 22398 | return set_parent(m_value.array->back(), old_capacity); |
| 22399 | } |
| 22400 | |
| 22401 | /// @brief add an object to an object if key does not exist |
| 22402 | /// @sa https://json.nlohmann.me/api/basic_json/emplace/ |