Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::basic_node::empty

boolean empty() const;

Tests whether the node value is empty.
If a basic_node is neither a sequence, mapping nor string, a fkyaml::type_error will be thrown.

Return Value

true if the node value is empty, false otherwise.

Examples

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

int main() {
    // create YAML nodes.
    std::vector<fkyaml::node> nodes = {
        fkyaml::node::sequence(),
        {1, 2, 3},
        {{"foo", true}, {"bar", false}},
        fkyaml::node(),
        true,
        256,
        3.14,
        "Hello, world!"};

    for (const auto& n : nodes) {
        try {
            // call empty()
            std::cout << std::boolalpha << n.empty() << std::endl;
        }
        catch (const fkyaml::exception& e) {
            std::cout << e.what() << std::endl;
        }
    }

    return 0;
}

output:

true
false
false
type_error: The target node is not of a container type. type=NULL_OBJECT
type_error: The target node is not of a container type. type=BOOLEAN
type_error: The target node is not of a container type. type=INTEGER
type_error: The target node is not of a container type. type=FLOAT
false

See Also