Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 899 Bytes

emplace.md

File metadata and controls

44 lines (29 loc) · 899 Bytes

jsoncons::basic_json::emplace

template <typename... Args>
array_iterator emplace(Args&&... args);

template <typename... Args>
array_iterator emplace(const_array_iterator pos, Args&&... args);

Constructs a new json element at the specified position of a json array, shifting all elements currently at or above that position to the right.

Parameters

pos

Iterator that identifies the position in the array to construct the new json value

args

Arguments to forward to the constructor of the json value

Return value

Array iterator pointing to the emplaced value.

Exceptions

Throws std::domain_error if not a json array.

Example

json a(json_array_arg);
a.emplace_back("Toronto");
a.emplace_back("Vancouver");
a.emplace(a.array_range().begin(),"Montreal");

std::cout << a << '\n';

Output:

["Montreal","Toronto","Vancouver"]