Path: blob/master/dep/rapidyaml/include/c4/yml/std/map.hpp
4270 views
#ifndef _C4_YML_STD_MAP_HPP_1#define _C4_YML_STD_MAP_HPP_23/** @file map.hpp write/read std::map to/from a YAML tree. */45#include "c4/yml/node.hpp"6#include <map>78namespace c4 {9namespace yml {1011// std::map requires child nodes in the data12// tree hierarchy (a MAP node in ryml parlance).13// So it should be serialized via write()/read().1415template<class K, class V, class Less, class Alloc>16void write(c4::yml::NodeRef *n, std::map<K, V, Less, Alloc> const& m)17{18*n |= c4::yml::MAP;19for(auto const& C4_RESTRICT p : m)20{21auto ch = n->append_child();22ch << c4::yml::key(p.first);23ch << p.second;24}25}2627template<class K, class V, class Less, class Alloc>28bool read(c4::yml::ConstNodeRef const& n, std::map<K, V, Less, Alloc> * m)29{30K k{};31V v{};32for(auto const& C4_RESTRICT ch : n)33{34ch >> c4::yml::key(k);35ch >> v;36m->emplace(std::make_pair(std::move(k), std::move(v)));37}38return true;39}4041} // namespace yml42} // namespace c44344#endif // _C4_YML_STD_MAP_HPP_454647