From 24925f6e85ce7ef88d505e05256e7611610a22cc Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 25 Oct 2022 17:14:43 +0000 Subject: [PATCH] Generalize std::map serialization templates ... ... to allow different sorting and/or allocators --- include/fc/io/raw.hpp | 8 ++++---- include/fc/io/raw_fwd.hpp | 6 ++++-- include/fc/variant.hpp | 18 +++++++++--------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 2b96f1e43..4fa6076bc 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -620,8 +620,8 @@ namespace fc { value.insert( std::move(tmp) ); } } - template - inline void pack( Stream& s, const std::map& value, uint32_t _max_depth ) { + template + inline void pack( Stream& s, const std::map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; fc::raw::pack( s, unsigned_int(value.size()), _max_depth ); @@ -632,8 +632,8 @@ namespace fc { ++itr; } } - template - inline void unpack( Stream& s, std::map& value, uint32_t _max_depth ) + template + inline void unpack( Stream& s, std::map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; diff --git a/include/fc/io/raw_fwd.hpp b/include/fc/io/raw_fwd.hpp index e82fe44a6..3fd6a61b9 100644 --- a/include/fc/io/raw_fwd.hpp +++ b/include/fc/io/raw_fwd.hpp @@ -67,8 +67,10 @@ namespace fc { template inline void pack( Stream& s, const std::unordered_map& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template inline void unpack( Stream& s, std::unordered_map& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); - template inline void pack( Stream& s, const std::map& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); - template inline void unpack( Stream& s, std::map& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template + inline void pack( Stream& s, const std::map& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template + inline void unpack( Stream& s, std::map& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); //template inline void pack( Stream& s, const flat_map& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); //template inline void unpack( Stream& s, flat_map& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); diff --git a/include/fc/variant.hpp b/include/fc/variant.hpp index 19cfae520..ae4f6ac46 100644 --- a/include/fc/variant.hpp +++ b/include/fc/variant.hpp @@ -111,10 +111,10 @@ namespace fc template void from_variant(const variant& var, flat_map& vo, uint32_t max_depth ); - template - void to_variant( const std::map& var, variant& vo, uint32_t max_depth ); - template - void from_variant( const variant& var, std::map& vo, uint32_t max_depth ); + template + void to_variant( const std::map& var, variant& vo, uint32_t max_depth ); + template + void from_variant( const variant& var, std::map& vo, uint32_t max_depth ); template void to_variant( const std::multimap& var, variant& vo, uint32_t max_depth ); template @@ -445,8 +445,8 @@ namespace fc for( const auto& item : vars ) vo.insert( item.as< std::pair >( max_depth - 1 ) ); } - template - void to_variant( const std::map& var, variant& vo, uint32_t max_depth ) + template + void to_variant( const std::map& var, variant& vo, uint32_t max_depth ) { _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" ); std::vector< variant > vars(var.size()); @@ -455,13 +455,13 @@ namespace fc vars[i++] = fc::variant( key_value, max_depth - 1 ); vo = vars; } - template - void from_variant( const variant& var, std::map& vo, uint32_t max_depth ) + template + void from_variant( const variant& var, std::map& vo, uint32_t max_depth ) { _FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" ); const variants& vars = var.get_array(); vo.clear(); - for( auto item : vars ) + for( const auto& item : vars ) vo.insert( item.as< std::pair >( max_depth - 1 ) ); }