Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::ordered_map::emplace

template <
    typename KeyType,
    detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
std::pair<iterator, bool> emplace(KeyType&& key, const mapped_type& value) noexcept;

Emplaces a new key-value pair if the new key does not exist in the ordered_map object.

KeyType
A type compatible with the key type.

Parameters

key [in]
A key to the target value.
value [in]
A value associated to the key.

Return Value

A pair consisting of an iterator to the inserted element, or the already-existing element if no insertion happend, and a boolean denoting the insertion took place (true if insertion happened, false otherwise).

Example
#include <iostream>
#include <fkYAML/node.hpp>

int main() {
    fkyaml::ordered_map<std::string, fkyaml::node> om = {{"foo", 123}, {"bar", "baz"}};

    for (auto& pair : om) {
        std::cout << pair.first << ": " << pair.second << std::endl;
    }
    return 0;
}

output:

foo: 123
bar: baz

See Also