Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::basic_node::get_value_ref

template <typename ReferenceType>
ReferenceType get_value_ref();

template <typename ReferenceType>
ReferenceType get_value_ref() const;

Deprecation

This function has been deprecated in version 0.4.3 and replaced with the following functions since it offers too verbose interface and that may confuse library users, given that only non-/const reference types to sequence_type, mapping_type, boolean_type, integer_type, float_number_type and string_type are accepted and that violating the limitation is not clear from error messages during compilation.

It will be removed in a future version. Please replace usages according to the following table.

from to
get_value_ref(),
get_value_ref()
as_seq()
get_value_ref(),
get_value_ref()
as_map()
get_value_ref(),
get_value_ref()
as_bool()
get_value_ref(),
get_value_ref()
as_int()
get_value_ref(),
get_value_ref()
as_float()
get_value_ref(),
get_value_ref()
as_str()

Explicit reference access to the internally stored YAML node value.
If the requested reference type does not match the current node value, a fkyaml::type_error will be thrown.

Note

If this function throws an exception, the internally stored YAML node value stays intact.

Template Parameters

ReferenceType

reference type to the target YAML node value.
It must be a (const) reference type to

Return Value

Reference to the internally stored YAML node value.

Examples

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

int main() {
    // create a YAML node.
    fkyaml::node n = 123;
    const fkyaml::node cn = 123;

    // get references to the value.
    auto& ref = n.as_int();
    auto& cref = cn.as_int();

    // print the referenced values
    std::cout << ref << std::endl;
    std::cout << cref << std::endl;

    // specifying incompatible reference type throws an exception
    try {
        auto iref = n.as_map();
    }
    catch (const fkyaml::exception& e) {
        std::cout << e.what() << std::endl;
    }

    return 0;
}

output:

123
123
type_error: The node value is not a mapping. type=INTEGER

See Also