From bdeefb48bf4d590e5e7860e4c8ee48cce01e6183 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Mon, 24 Mar 2014 11:46:23 -0400 Subject: [PATCH] adding std::map<> conversions to/from variant --- include/fc/variant.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/fc/variant.hpp b/include/fc/variant.hpp index bb36a0d..7cb8890 100644 --- a/include/fc/variant.hpp +++ b/include/fc/variant.hpp @@ -6,6 +6,7 @@ #include // memset #include #include +#include #include namespace fc @@ -47,6 +48,10 @@ namespace fc void to_variant( const std::unordered_map& var, variant& vo ); template void from_variant( const variant& var, std::unordered_map& vo ); + template + void to_variant( const std::map& var, variant& vo ); + template + void from_variant( const variant& var, std::map& vo ); template void to_variant( const std::unordered_set& var, variant& vo ); @@ -314,6 +319,23 @@ namespace fc vo.insert( itr->as< std::pair >() ); } + template + void to_variant( const std::map& var, variant& vo ) + { + std::vector< variant > vars(var.size()); + size_t i = 0; + for( auto itr = var.begin(); itr != var.end(); ++itr, ++i ) + vars[i] = fc::variant(*itr); + vo = vars; + } + template + void from_variant( const variant& var, std::map& vo ) + { + const variants& vars = var.get_array(); + vo.clear(); + for( auto itr = vars.begin(); itr != vars.end(); ++itr ) + vo.insert( itr->as< std::pair >() ); + } template