fork download
  1. #include <iostream>
  2. #include <set>
  3.  
  4. struct Point
  5. {
  6. Point(double x, double y)
  7. : x(x)
  8. , y(y)
  9. {
  10.  
  11. }
  12.  
  13. friend bool operator < (const Point& lhs, const Point& rhs);
  14. friend bool operator == (const Point& lhs, const Point& rhs);
  15.  
  16. double x;
  17. double y;
  18. };
  19.  
  20. bool operator < (const Point& lhs, const Point& rhs)
  21. {
  22. return lhs.x < rhs.x;
  23. }
  24.  
  25. bool operator == (const Point& lhs, const Point& rhs)
  26. {
  27. return lhs.x == rhs.x && lhs.y == rhs.y;
  28. }
  29.  
  30. int main()
  31. {
  32. std::set<Point> points = { Point(42.0, 50.0), Point(1.0, 2.0), Point(42.0, 50.0) };
  33.  
  34. for (const auto& p : points)
  35. {
  36. std::cout << p.x << ", " << p.y << std::endl;
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
1, 2
42, 50