Skip to content

Commit

Permalink
Add serialiation support for std::multimap
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJoswiak committed Sep 14, 2019
1 parent 953af1a commit 8d75039
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/types/map.hpp
Expand Up @@ -22,6 +22,17 @@ void Save(OutputArchive& oa, const std::map<K, V, Compare, Allocator>& map) {
}
}

template<typename K, typename V, typename Compare, typename Allocator>
void
Save(OutputArchive& oa,
const std::multimap<K, V, Compare, Allocator>& map) {
oa(map.size());
for (const auto& kv : map) {
oa(kv.first);
oa(kv.second);
}
}

// Deserialize the map by reading the number of elements stored, then reading
// each key-value pair.
template<typename K, typename V, typename Compare, typename Allocator>
Expand All @@ -43,6 +54,23 @@ void Load(binary::InputArchive& ia, std::map<K, V, Compare, Allocator>& map) {
}
}

template<typename K, typename V, typename Compare, typename Allocator>
void
Load(binary::InputArchive& ia,
std::multimap<K, V, Compare, Allocator>& map) {
std::size_t size;
ia(size);

for (std::size_t i = 0; i < size; ++i) {
K key;
V value;
ia(key);
ia(value);

map.emplace(std::move(key), std::move(value));
}
}

} // namespace binary
} // namespace draft

Expand Down

0 comments on commit 8d75039

Please sign in to comment.