Skip to content

Commit eae7f10

Browse files
committed
map_difference: Allow on unordered_map
This patch changes the map_difference interface so difference() can be called on on unordered_maps. Signed-off-by: Duarte Nunes <[email protected]>
1 parent 7dc895e commit eae7f10

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

map_difference.hh

+10-14
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,22 @@ struct map_difference {
4646
{ }
4747
};
4848

49+
/**
50+
* Produces a map_difference between the two specified maps, with Key keys and
51+
* Tp values, using the provided equality function. In order to work with any
52+
* map type, such as std::map and std::unordered_map, Args holds the remaining
53+
* type parameters of the particular map type.
54+
*/
4955
template<template<typename...> class Map,
5056
typename Key,
5157
typename Tp,
52-
typename Compare = std::less<Key>,
5358
typename Eq = std::equal_to<Tp>,
54-
typename Alloc>
59+
typename... Args>
5560
inline
5661
map_difference<Key>
57-
difference(const Map<Key, Tp, Compare, Alloc>& left,
58-
const Map<Key, Tp, Compare, Alloc>& right,
59-
Compare key_comp = Compare(),
60-
Eq equals = Eq(),
61-
Alloc alloc = Alloc())
62+
difference(const Map<Key, Tp, Args...>& left,
63+
const Map<Key, Tp, Args...>& right,
64+
Eq equals = Eq())
6265
{
6366
map_difference<Key> diff{};
6467
for (auto&& kv : right) {
@@ -82,10 +85,3 @@ difference(const Map<Key, Tp, Compare, Alloc>& left,
8285
}
8386
return diff;
8487
}
85-
86-
template<typename Key, typename Tp, typename Compare, typename Eq, typename Alloc>
87-
inline
88-
map_difference<Key>
89-
difference(const std::map<Key, Tp, Compare, Alloc>& left, const std::map<Key, Tp, Compare, Alloc>& right, Eq equals) {
90-
return difference(left, right, left.key_comp(), equals);
91-
}

0 commit comments

Comments
 (0)