Defined in header <fkYAML/node.hpp>
fkyaml::basic_node::mapping_type¶
The type used to store mapping values.
The actual type is defined by the template parameter MappingType
.
If not explicitly specified, the default type std::map
is defined.
With the decided container type, the type of mapping objects will then be decided in the form of MappingType<basic_node, basic_node>
with which mapping objects are stored inside a basic_node
.
Note that mapping values are stored as a pointer to an allocated memory area on the heap in a basic_node
so that the internal storage size will at most be 8 bytes.
Preserve the insertion order of key-value pairs
The YAML specification describes as a mapping node as "an unordered association of unique keys to values".
Which means that the insertion order of key-value pairs are not guranteed by the YAML specification.
To follow the specification, the fkYAML library uses std::map
as the mapping container type by default with the intention of better integration with other C++ programs.
If mapping values needs to be dependent on the insertion order, you can force preserving the insertion order by specifying fkyaml::ordered_map
as the MappingType template parameter as follows:
Examples¶
Example
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <type_traits>
#include <fkYAML/node.hpp>
int main() {
std::cout << std::boolalpha << std::is_same<std::map<std::string, fkyaml::node>, fkyaml::node::mapping_type>::value
<< std::endl;
return 0;
}
output: