| 21951 | */ |
| 21952 | template<class... Args> |
| 21953 | std::pair<iterator, bool> emplace(Args&& ... args) |
| 21954 | { |
| 21955 | // emplace only works for null objects or arrays |
| 21956 | if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object()))) |
| 21957 | { |
| 21958 | JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name()))); |
| 21959 | } |
| 21960 | |
| 21961 | // transform null object into an object |
| 21962 | if (is_null()) |
| 21963 | { |
| 21964 | m_type = value_t::object; |
| 21965 | m_value = value_t::object; |
| 21966 | assert_invariant(); |
| 21967 | } |
| 21968 | |
| 21969 | // add element to array (perfect forwarding) |
| 21970 | auto res = m_value.object->emplace(std::forward<Args>(args)...); |
| 21971 | // create result iterator and set iterator to the result of emplace |
| 21972 | auto it = begin(); |
| 21973 | it.m_it.object_iterator = res.first; |
| 21974 | |
| 21975 | // return pair of iterator and boolean |
| 21976 | return { it, res.second }; |
| 21977 | } |
| 21978 | |
| 21979 | /// Helper for insertion of an iterator |
| 21980 | /// @note: This uses std::distance to support GCC 4.8, |