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
The problem is that std::unordered_set is using std::hash template to compute hashes for its entries and there is no std::hash
specialization for pairs. So you will have to do two things:
std::hash
for your key type (std::pair
) using that function.Here is a simple example:
#include
namespace std {
template <> struct hash> {
inline size_t operator()(const std::pair &v) const {
std::hash int_hasher;
return int_hasher(v.first) ^ int_hasher(v.second);
}
};
}
int main()
{
std::unordered_set< std::pair > edge;
}