| 22509 | /// @sa https://json.nlohmann.me/api/basic_json/emplace_back/ |
| 22510 | template<class... Args> |
| 22511 | reference emplace_back(Args&& ... args) |
| 22512 | { |
| 22513 | // emplace_back only works for null objects or arrays |
| 22514 | if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) |
| 22515 | { |
| 22516 | JSON_THROW(type_error::create(311, detail::concat("cannot use emplace_back() with ", type_name()), this)); |
| 22517 | } |
| 22518 | |
| 22519 | // transform null object into an array |
| 22520 | if (is_null()) |
| 22521 | { |
| 22522 | m_data.m_type = value_t::array; |
| 22523 | m_data.m_value = value_t::array; |
| 22524 | assert_invariant(); |
| 22525 | } |
| 22526 | |
| 22527 | // add element to array (perfect forwarding) |
| 22528 | const auto old_capacity = m_data.m_value.array->capacity(); |
| 22529 | m_data.m_value.array->emplace_back(std::forward<Args>(args)...); |
| 22530 | return set_parent(m_data.m_value.array->back(), old_capacity); |
| 22531 | } |
| 22532 | |
| 22533 | /// @brief add an object to an object if key does not exist |
| 22534 | /// @sa https://json.nlohmann.me/api/basic_json/emplace/ |