From e592f83e65f5bdf4a2435912395af010d5028d1a Mon Sep 17 00:00:00 2001 From: Vincent Cogne Date: Tue, 7 Jun 2016 19:17:53 +0200 Subject: [PATCH] Add a converter for std::array --- include/yaml-cpp/node/convert.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index f388a67..5b6cc10 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -241,6 +241,35 @@ struct convert > { } }; +// std::array +template +struct convert > { + static Node encode(const std::array& rhs) { + Node node(NodeType::Sequence); + for (typename std::array::const_iterator it = rhs.begin(); + it != rhs.end(); ++it) + node.push_back(*it); + return node; + } + + static bool decode(const Node& node, std::array& rhs) { + if (!node.IsSequence()) + return false; + + std::size_t index = 0; + for (const_iterator it = node.begin(); it != node.end(); ++it) { +#if defined(__GNUC__) && __GNUC__ < 4 + // workaround for GCC 3: + rhs.at(index) = it->template as(); +#else + rhs.at(index) = it->as(); +#endif + ++index; + } + return true; + } +}; + // std::pair template struct convert > {