Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::basic_node::as_seq

sequence_type& as_seq();
const sequence_type& as_seq() const;

Returns (const) reference to the sequence node value.
If the current node value is not an sequence, a fkyaml::type_error will be thrown.

Return Value

(const) reference to the sequence node value.

Examples

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

int main() {
    // create a sequence node.
    fkyaml::node n = {true, 3.14};

    // get reference to the sequence value from a non-const node.
    // use `auto&` or `fkyaml::node::sequence_type&` for forward compatibility.
    auto& s = n.as_seq();
    // get const reference to the sequence value from a const node.
    const fkyaml::node cn = n;
    const auto& cs = cn.as_seq();

    // modify the sequence value.
    s.emplace_back(123);
    s.emplace_back("foo");

    for (auto& elem : s) {
        std::cout << elem << std::endl;
    }
    std::cout << std::endl;
    for (const auto& celem : cs) {
        std::cout << celem << std::endl;
    }
}

output:

true
3.14
123
foo

true
3.14

See Also