fork download
  1. #include <iostream>
  2. #include <set>
  3.  
  4. typedef std::pair<int, int> pairs;
  5.  
  6. int main()
  7. {
  8. auto compare = [](pairs lhs, pairs rhs) //custom compare lambda function
  9. {
  10. if(lhs.first > lhs.second ) lhs = pairs{lhs.second, lhs.first };
  11. if(rhs.first > rhs.second ) rhs = pairs{rhs.second, rhs.first };
  12. return lhs< rhs;
  13. };
  14.  
  15. std::set<pairs, decltype(compare)> Set(compare);
  16.  
  17. Set.emplace(std::make_pair(0,1)); // use can also emplace to the Set
  18. Set.emplace(pairs{0,2});
  19. Set.emplace(pairs{1,0});
  20.  
  21. for(const auto& it: Set)
  22. std::cout << it.first << " " << it.second << std::endl;
  23. }
Success #stdin #stdout 0s 4496KB
stdin
Standard input is empty
stdout
0 1
0 2