MCPcopy Create free account
hub / github.com/AlexandreRouma/SDRPlusPlus / insert

Function insert

core/src/json.hpp:21922–21938  ·  view source on GitHub ↗

! @brief inserts element Inserts element @a val before iterator @a pos. @param[in] pos iterator before which the content will be inserted; may be the end() iterator @param[in] val element to insert @return iterator pointing to the inserted @a val. @throw type_error.309 if called on JSON values other than arrays; example: `"cannot use insert() with string"` @t

Source from the content-addressed store, hash-verified

21920 @since version 1.0.0
21921 */
21922 iterator insert(const_iterator pos, const basic_json& val)
21923 {
21924 // insert only works for arrays
21925 if (JSON_HEDLEY_LIKELY(is_array()))
21926 {
21927 // check if iterator pos fits to this JSON value
21928 if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
21929 {
21930 JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
21931 }
21932
21933 // insert to array and return iterator
21934 return insert_iterator(pos, val);
21935 }
21936
21937 JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
21938 }
21939
21940 /*!
21941 @brief inserts element

Callers

nothing calls this directly

Calls 7

is_arrayFunction · 0.85
insert_iteratorFunction · 0.85
type_nameFunction · 0.85
is_objectFunction · 0.85
createFunction · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected