Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::ordered_map::find

template <
    typename KeyType,
    detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
iterator find(KeyType&& key) noexcept;

template <
    typename KeyType,
    detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
const_iterator find(KeyType&& key) const noexcept;

Find a value with the given key.

Template Parameters

KeyType
A type compatible with the key type.

Parameters

key [in]
A key to the target value.

Return Value

An iterator to the target value if found, the result of end() otherwise.

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

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

    // insert a value with a new key.
    auto ret = om.emplace("qux", 3.14);
    if (ret.second) {
        std::cout << "emplacement took place." << std::endl;
    }
    std::cout << ret.first->second << std::endl;

    // insert a value with an existing key.
    auto ret2 = om.emplace("foo", true);
    if (!ret2.second) {
        std::cout << "emplacement did not take place." << std::endl;
    }
    std::cout << ret2.first->second << std::endl;

    return 0;
}

output:

emplacement took place.
3.14
emplacement did not take place.
123

See Also