Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::basic_node::as_uint

uint64_t as_uint() const;

Returns the integer node value as an unsigned 64-bit integer.
If the current node value is not a positive integer, a fkyaml::type_error will be thrown.

Return Value

the integer node value as an unsigned 64-bit integer.

Examples

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

int main() {
    using namespace fkyaml::literals;

    // create a integer node.
    fkyaml::node n = "v: 15745692345339290292"_yaml;
    auto& v = n["v"];

    // get the integer value as an unsingned 64-bit integer from a non-const node.
    auto i = v.as_uint();

    std::cout << i << std::endl;

    // as_uint() throws `fkyaml::type_error` when the node value is not an unsigned integer.
    v = -123;
    try {
        auto j = v.as_uint();
    }
    catch (const fkyaml::type_error& e) {
        std::cout << e.what() << std::endl;
    }
}

output:

15745692345339290292
type_error: The node value cannot be represented as an unsigned integer. type=INTEGER

See Also