fork(3) 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.  
  21. for (int x : s)
  22. cout << x << ' ';
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1 10 100 11