MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / emplace_back

Function emplace_back

include/behaviortree_cpp/contrib/json.hpp:22511–22531  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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/

Callers 1

emplaceFunction · 0.85

Calls 6

is_nullFunction · 0.85
is_arrayFunction · 0.85
createFunction · 0.85
concatFunction · 0.85
set_parentFunction · 0.85
type_nameFunction · 0.70

Tested by

no test coverage detected