I am trying to create an std::unordered_map with an std::pair as key. As you can imagine, this would require me to explicitly provide a class to generate a hash for a given
You need to make the operator()
a const method in your custom functors.
Apparently, libstdc++ refers to your hash object via const PairHash<int, int>*
. Thus calling the operator ()
which is not marked const
in your program is a compiler error.
You can get your code to compile with libstdc++ by making operator()
const
.
As of 17.6.3.4 (Hash Requirements), a Hash type must provide a size_t operator(KeyType) const;
, so your code is indeed incorrect.