, , int -, mod %
struct IntMod {
constexpr std::size_t operator()(int i) const { return i % 10; }
};
std::unordered_set<int, IntMod> s;
, , , , .
s.insert(25);
s.insert(35);
assert(*s.find(25) == 25);
assert(*s.find(35) == 35);
If we add KeyEqualthat just uses a hash function (for example, you suggest doing it by default), it splits into the second insert.
struct IntEq {
constexpr bool operator()(int a, int b) const {
return IntMod{}(a) == IntMod{}(b);
}
};
std::unordered_set<int, IntMod, IntEq> s;
s.insert(25);
s.insert(35);
assert(*s.find(25) == 25);
assert(*s.find(35) == 35);
source
share