Defined in header <fkYAML/node.hpp>
fkyaml::basic_node::operator<¶
Check if this object is less than rhs according to the following rules:
- If the values are of the same
node_typetype, their stored values are compared according to their respectiveoperator<. - Two
basic_nodeobjects are always equal if both of them are of thenode_type::NULL_OBJECTtype. - If the values are of different
node_typetypes, the stored values are ignored and the order of the types are considered. The order of the types is as followed (top < bottom):- node_type::SEQUENCE
- node_type::MAPPING
- node_type::NULL_OBJECT
- node_type::BOOLEAN
- node_type::INTEGER
- node_type::FLOAT
- node_type::STRING
- If the values are of the
node_type::BOOLEANtype, a value whose stored value isfalseis less than a value whose stored value istrue.
Parameters¶
rhs[in]- A
basic_nodeobject to compared with.
Return Value¶
true if this is less than rhs, false otherwise.
Examples¶
Example
#include <iomanip>
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
// create YAML nodes.
fkyaml::node seq_1 = {1, 2, 3};
fkyaml::node seq_2 = {1, 2, 4};
fkyaml::node map_1 = {{"foo", true}, {"bar", 123}};
fkyaml::node map_2 = {{"bar", 123}, {"foo", true}};
fkyaml::node null_1 = nullptr;
fkyaml::node null_2 = nullptr;
fkyaml::node bool_1 = false;
fkyaml::node bool_2 = true;
fkyaml::node integer_1 = 321;
fkyaml::node integer_2 = 123;
fkyaml::node float_1 = 1.23;
fkyaml::node float_2 = 3.14;
fkyaml::node string_1 = "foo";
fkyaml::node string_2 = "bar";
// the same type
std::cout << std::boolalpha;
std::cout << (seq_1 < seq_2) << std::endl;
std::cout << (map_1 < map_2) << std::endl;
std::cout << (null_1 < null_2) << std::endl;
std::cout << (bool_1 < bool_2) << std::endl;
std::cout << (integer_1 < integer_2) << std::endl;
std::cout << (float_1 < float_2) << std::endl;
std::cout << (string_1 < string_2) << std::endl;
// different types
std::cout << (bool_1 < string_1) << std::endl;
std::cout << (float_2 < seq_2) << std::endl;
return 0;
}
output: