Defined in header <fkYAML/node.hpp>
fkyaml::basic_node::alias_of¶
Creates an alias YAML node from an anchor node.
If the given anchor node does not have any non-empty anchor name, an fkyaml::exception
will be thrown.
Parameters¶
- anchor [in]
- A basic_node object with an anchor name.
This node must have a non-empty anchor name.
Return Value¶
An alias node which refers to the given anchor node.
Note
If this API throws an exception, the internally stored YAML node value in the given anchor node stays intact.
Examples¶
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
// create a YAML node.
fkyaml::node anchor_node = "test";
// add an anchor name to the node.
anchor_node.add_anchor_name("anchor");
// create an alias YAML node.
fkyaml::node alias_node = fkyaml::node::alias_of(anchor_node);
// print the value in the alias node.
std::cout << alias_node.as_str() << std::endl;
return 0;
}
output: