fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <set>
  4. #include <type_traits>
  5. using namespace std;
  6.  
  7. bool lexical_compare(int a, int b) {
  8. return to_string(a) < to_string(b);
  9. }
  10.  
  11. using LexicalCompare = std::integral_constant<decltype(&lexical_compare), &lexical_compare>;
  12.  
  13. int main() {
  14. set<int, LexicalCompare> s;
  15.  
  16. s.insert(1);
  17. s.insert(10);
  18. s.insert(11);
  19. s.insert(100);
  20. s.insert(100);
  21. s.insert(100);
  22. s.insert(102);
  23. s.insert(103);
  24.  
  25. for (int x : s)
  26. cout << x << ' ';
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
1 10 100 102 103 11