fork download
  1. #include <unordered_set>
  2.  
  3. class Point
  4. {
  5. public:
  6. struct Hash
  7. {
  8. size_t operator()(Point const & x) const noexcept
  9. {
  10. return (
  11. (51 + std::hash<int>()(x.getX())) * 51 +
  12. std::hash<int>()(x.getY())
  13. );
  14. }
  15. };
  16.  
  17. Point(int x, int y) : x_(x), y_(y) {}
  18.  
  19. int getX() const { return x_; }
  20. int getY() const { return y_; }
  21.  
  22. bool operator==(Point const & rhs) const
  23. {
  24. return x_ == rhs.getX() &&
  25. y_ == rhs.getY();
  26. }
  27.  
  28. bool operator!=(Point const & rhs) const { return !(*this == rhs); }
  29.  
  30. private:
  31. int x_, y_;
  32. };
  33.  
  34. typedef std::unordered_set<Point, Point::Hash> PointSet;
  35.  
  36. int main()
  37. {
  38. PointSet x;
  39. x.insert(Point(1,2));
  40. return 0;
  41. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty