Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::basic_node::erase

template <typename KeyType>
size_type erase(KeyType&& key);

Erases the entry with the given key from a YAML mapping node.
If the node value is not a mapping, a fkyaml::type_error will be thrown.

The input parameter key must be either a basic_node object or an object of a compatible type, i.e., a type from which a basic_node object can be constructed.

Template Parameters

KeyType
A type from which a basic_node object can be constructed.

Parameters

key [in]
A key identifying the mapping entry to erase.

Return Value

The number of erased entries (0 or 1).

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

int main() {
    // create a YAML mapping node.
    fkyaml::node n = {{"foo", true}, {"bar", 123}};

    // erase entries by compatible and node keys.
    std::cout << n.erase("foo") << std::endl;
    std::cout << n.erase(fkyaml::node("baz")) << std::endl;

    // confirm that the erased key no longer exists.
    std::cout << std::boolalpha << n.contains("foo") << std::endl;

    return 0;
}

output:

1
0
false

See Also