I'm still learning how to use the standard library containers std::map
and std::unordered_map
. I have recently tried to provide a hash function or comparison function.
There are two things I don't understand:
std::map<int, int, equal_to<int>> myMap1; // Works
std::map<int, int, hash<int>> myMap2; // Works
std::unordered_map<int, int, equal_to<int>> myMap3; // Doesn't work
std::unordered_map<int, int, hash<int>> myMap4; // Works
Why can I provide a hash function for std::map
while I can't provide a comparison function to a std::unordered_map
?
Also, if I use a custom struct for the comparison function std::equal_to
without overloading the ==
operator I get no errors. Why is that so?