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