In order to make std::unordered_set
work with your Point
class, you can provide a std::hash
specialization for it:
namespace std
{
template<>
struct hash<Point> {
size_t operator()(const Point &pt) const {
return std::hash<int>()(pt.x) ^ std::hash<int>()(pt.y);
}
};
}
You could also change std::unordered_set
's second template parameter(it defaults to std::hash<Point>
), which indicates a functor type that returns the required hash.
It seems like you tried providing this hash implementation via a user defined conversion to size_t
, but that won't work. The fact that it works in VC is caused by some bug in their implementation.