fork(43) download
  1. #include <string>
  2. #include <map>
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. auto comp = [](const std::string& a, const std::string& b) { return a.length() < b.length(); };
  8. std::map<std::string, std::string, decltype(comp)> my_map(comp);
  9.  
  10. my_map["1"] = "a";
  11. my_map["three"] = "b";
  12. my_map["two"] = "c";
  13. my_map["fouuur"] = "d";
  14.  
  15. for(auto const &kv : my_map)
  16. std::cout << kv.first << std::endl;
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 4164KB
stdin
Standard input is empty
stdout
1
two
three
fouuur