Defined in header <fkYAML/node.hpp>
fkyaml::basic_node::as_bool¶
Returns (const) reference to the boolean node value.
If the current node value is not a boolean, a fkyaml::type_error
will be thrown.
Return Value¶
(const) reference to the boolean node value.
Examples¶
Example
#include <iostream>
#include <iomanip>
#include <fkYAML/node.hpp>
int main() {
// create a boolean node.
fkyaml::node n = true;
// get reference to the boolean value from a non-const node.
// use `auto&` or `fkyaml::node::boolean_type&` for forward compatibility.
auto& b = n.as_bool();
// get const reference to the boolean value from a const node.
const fkyaml::node cn = n;
const auto& cb = cn.as_bool();
// modify the boolean value.
b = false;
std::cout << std::boolalpha << b << std::endl;
std::cout << std::boolalpha << cb << std::endl;
}
output: