Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize std::map serialization templates to allow different sorting and/or allocators #246

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/fc/io/raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ namespace fc {
value.insert( std::move(tmp) );
}
}
template<typename Stream, typename K, typename V>
inline void pack( Stream& s, const std::map<K,V>& value, uint32_t _max_depth ) {
template<typename Stream, typename K, typename... V>
inline void pack( Stream& s, const std::map<K, V...>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
Expand All @@ -632,8 +632,8 @@ namespace fc {
++itr;
}
}
template<typename Stream, typename K, typename V>
inline void unpack( Stream& s, std::map<K,V>& value, uint32_t _max_depth )
template<typename Stream, typename K, typename V, typename... A>
inline void unpack( Stream& s, std::map<K, V, A...>& value, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
--_max_depth;
Expand Down
6 changes: 4 additions & 2 deletions include/fc/io/raw_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ namespace fc {
template<typename Stream, typename K, typename V> inline void pack( Stream& s, const std::unordered_map<K,V>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename K, typename V> inline void unpack( Stream& s, std::unordered_map<K,V>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );

template<typename Stream, typename K, typename V> inline void pack( Stream& s, const std::map<K,V>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename K, typename V> inline void unpack( Stream& s, std::map<K,V>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename K, typename... V>
inline void pack( Stream& s, const std::map<K, V...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename K, typename V, typename... A>
inline void unpack( Stream& s, std::map<K, V, A...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );

//template<typename Stream, typename K, typename... V> inline void pack( Stream& s, const flat_map<K,V...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
//template<typename Stream, typename K, typename V, typename... A> inline void unpack( Stream& s, flat_map<K,V,A...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
Expand Down
18 changes: 9 additions & 9 deletions include/fc/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ namespace fc
template<typename K, typename T, typename... A>
void from_variant(const variant& var, flat_map<K, T, A...>& vo, uint32_t max_depth );

template<typename K, typename T>
void to_variant( const std::map<K,T>& var, variant& vo, uint32_t max_depth );
template<typename K, typename T>
void from_variant( const variant& var, std::map<K,T>& vo, uint32_t max_depth );
template<typename K, typename... T>
void to_variant( const std::map<K, T...>& var, variant& vo, uint32_t max_depth );
template<typename K, typename T, typename... A>
void from_variant( const variant& var, std::map<K, T, A...>& vo, uint32_t max_depth );
template<typename K, typename T>
void to_variant( const std::multimap<K,T>& var, variant& vo, uint32_t max_depth );
template<typename K, typename T>
Expand Down Expand Up @@ -445,8 +445,8 @@ namespace fc
for( const auto& item : vars )
vo.insert( item.as< std::pair<K,T> >( max_depth - 1 ) );
}
template<typename K, typename T>
void to_variant( const std::map<K, T>& var, variant& vo, uint32_t max_depth )
template<typename K, typename... T>
void to_variant( const std::map<K, T...>& var, variant& vo, uint32_t max_depth )
{
_FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
std::vector< variant > vars(var.size());
Expand All @@ -455,13 +455,13 @@ namespace fc
vars[i++] = fc::variant( key_value, max_depth - 1 );
vo = vars;
}
template<typename K, typename T>
void from_variant( const variant& var, std::map<K, T>& vo, uint32_t max_depth )
template<typename K, typename T, typename... A>
void from_variant( const variant& var, std::map<K, T, A...>& 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<K,T> >( max_depth - 1 ) );
}

Expand Down