fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. struct Point
  6. {
  7. Point(double x, double y)
  8. : x(x)
  9. , y(y)
  10. {
  11.  
  12. }
  13.  
  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 && lhs.y == rhs.y;
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28. std::vector<Point> points = { Point(42.0, 50.0), Point(1.0, 2.0), Point(42.0, 50.0) };
  29. std::sort(points.begin(), points.end(), [](const Point& lhs, const Point& rhs)
  30. {
  31. return lhs.x < rhs.x;
  32. });
  33.  
  34. points.erase(std::unique(points.begin(), points.end()), points.end());
  35.  
  36. for (const auto& p : points)
  37. {
  38. std::cout << p.x << ", " << p.y << std::endl;
  39. }
  40. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
1, 2
42, 50