MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / emplace

Function emplace

Source/Utils/json.hpp:21953–21977  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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,

Callers 2

ordered_mapClass · 0.85
insertMethod · 0.85

Calls 7

is_nullFunction · 0.85
is_objectFunction · 0.85
createFunction · 0.85
type_nameFunction · 0.85
assert_invariantFunction · 0.85
emplaceMethod · 0.80
beginFunction · 0.70

Tested by

no test coverage detected