The following program does not compile an unordered set of pairs of integers, but it does for integers. Can unordered_set
and its member functions be used on us
As already mentioned in most of the other answers on this question, you need to provide a hash function for std::pair
. However, since C++11, you can also use a lambda expression instead of defining a hash function. The following code takes the solution given by dasblinkenlight as basis:
auto hash = [](const std::pair& p){ return p.first * 31 + p.second; };
std::unordered_set, decltype(hash)> u_edge_(8, hash);
Code on Ideone
I'd like repeat dasblinkenlight's disclaimer: This solution is limited to a pair of two integers. This answer provides the idea for a more general solution.