fork download
  1. #include <set>
  2. #include <iostream>
  3.  
  4. using pair_type = std::pair<int, int>;
  5.  
  6. auto comp = [](const pair_type& a, const pair_type& b) {
  7. return (a.first < b.first) || ((a.first == b.first) && (a.second < b.second));
  8. };
  9.  
  10. class A{
  11. public:
  12. A() : edge_(comp) {}
  13. void test();
  14. private:
  15. std::set<pair_type, decltype(comp)> edge_;
  16. };
  17.  
  18. void A::test()
  19. {
  20. edge_.insert(std::make_pair(3, 2));
  21. edge_.insert(std::make_pair(1, 2));
  22. edge_.insert(std::make_pair(2, 1));
  23. edge_.insert(std::make_pair(1, 1));
  24.  
  25. for (auto const &e : edge_)
  26. std::cout << e.first << " - " << e.second << std::endl;
  27. }
  28.  
  29. int main()
  30. {
  31. A a;
  32. a.test();
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 4348KB
stdin
Standard input is empty
stdout
1 - 1
1 - 2
2 - 1
3 - 2