@brief add an object to an array @sa https://json.nlohmann.me/api/basic_json/push_back/
| 3115 | /// @brief add an object to an array |
| 3116 | /// @sa https://json.nlohmann.me/api/basic_json/push_back/ |
| 3117 | void push_back(basic_json&& val) |
| 3118 | { |
| 3119 | // push_back only works for null objects or arrays |
| 3120 | if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) |
| 3121 | { |
| 3122 | JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this)); |
| 3123 | } |
| 3124 | |
| 3125 | // transform a null object into an array |
| 3126 | if (is_null()) |
| 3127 | { |
| 3128 | m_data.m_type = value_t::array; |
| 3129 | m_data.m_value = value_t::array; |
| 3130 | assert_invariant(); |
| 3131 | } |
| 3132 | |
| 3133 | // add the element to the array (move semantics) |
| 3134 | const auto old_capacity = m_data.m_value.array->capacity(); |
| 3135 | m_data.m_value.array->push_back(std::move(val)); |
| 3136 | set_parent(m_data.m_value.array->back(), old_capacity); |
| 3137 | // if val is moved from, basic_json move constructor marks it null, so we do not call the destructor |
| 3138 | } |
| 3139 | |
| 3140 | /// @brief add an object to an array |
| 3141 | /// @sa https://json.nlohmann.me/api/basic_json/operator+=/ |
no test coverage detected