MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / emplace

Function emplace

3rd/nlohmann_json/include/nlohmann/json.hpp:5694–5720  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5692 */
5693 template<class... Args>
5694 std::pair<iterator, bool> emplace(Args&& ... args)
5695 {
5696 // emplace only works for null objects or arrays
5697 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
5698 {
5699 JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name()), *this));
5700 }
5701
5702 // transform null object into an object
5703 if (is_null())
5704 {
5705 m_type = value_t::object;
5706 m_value = value_t::object;
5707 assert_invariant();
5708 }
5709
5710 // add element to array (perfect forwarding)
5711 auto res = m_value.object->emplace(std::forward<Args>(args)...);
5712 set_parent(res.first->second);
5713
5714 // create result iterator and set iterator to the result of emplace
5715 auto it = begin();
5716 it.m_it.object_iterator = res.first;
5717
5718 // return pair of iterator and boolean
5719 return {it, res.second};
5720 }
5721
5722 /// Helper for insertion of an iterator
5723 /// @note: This uses std::distance to support GCC 4.8,

Callers 2

ordered_mapClass · 0.70
insertMethod · 0.70

Calls 8

stringFunction · 0.85
is_nullFunction · 0.70
is_objectFunction · 0.70
createFunction · 0.70
type_nameFunction · 0.70
set_parentFunction · 0.70
beginFunction · 0.70
emplaceMethod · 0.45

Tested by

no test coverage detected