fork(4) download
  1. #include <set>
  2. #include <iostream>
  3.  
  4. class Foo {
  5. public:
  6. Foo(int v1, int v2) : val1(v1), val2(v2) {};
  7. bool operator<(const Foo &foo) const { return val2 < foo.val2; }
  8. int val1;
  9. int val2;
  10. };
  11.  
  12. int main()
  13. {
  14. std::multiset<Foo> ms;
  15. ms.insert(Foo(1, 6));
  16. ms.insert(Foo(1, 5));
  17. ms.insert(Foo(3, 4));
  18. ms.insert(Foo(2, 4));
  19.  
  20. for (auto const &foo : ms)
  21. std::cout << foo.val1 << " " << foo.val2 << std::endl;
  22.  
  23. std::cout << std::endl;
  24. std::set<Foo> s;
  25. s.insert(Foo(1, 6));
  26. s.insert(Foo(1, 5));
  27. s.insert(Foo(3, 4));
  28. s.insert(Foo(2, 4));
  29.  
  30. for (auto const &foo : s)
  31. std::cout << foo.val1 << " " << foo.val2 << std::endl;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
3 4
2 4
1 5
1 6

3 4
1 5
1 6