fork(1) download
  1. #include <set>
  2. #include <iostream>
  3.  
  4. struct Point {
  5. int x, y;
  6. };
  7.  
  8. int main() {
  9. auto comp = [](const Point& p1, const Point& p2) {
  10. return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y);
  11. };
  12. std::set<Point, decltype(comp)> mySet({ {2, 1}, {1, 2} }, comp);
  13.  
  14. Point myPoint;
  15. myPoint.x = 1;
  16. myPoint.y = 3;
  17. mySet.insert(myPoint);
  18.  
  19. for (auto const& pt : mySet) {
  20. std::cout << "(" << pt.x << ", " << pt.y << ")" << std::endl;
  21. }
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 4500KB
stdin
Standard input is empty
stdout
(1, 2)
(1, 3)
(2, 1)