fork(4) download
  1. #include <cctype>
  2. bool case_insensitive_cmp(char lhs, char rhs)
  3. {
  4. return std::toupper(lhs) < std::toupper(rhs);
  5. }
  6.  
  7. #include <algorithm>
  8. #include <string>
  9. bool case_insensitive_string_cmp(const std::string& lhs,
  10. const std::string& rhs)
  11. {
  12. return std::lexicographical_compare(lhs.begin(),
  13. lhs.end(),
  14. rhs.begin(),
  15. rhs.end(),
  16. case_insensitive_cmp);
  17. }
  18.  
  19. #include <map>
  20. #include <iostream>
  21.  
  22. int main()
  23. {
  24. std::map<std::string,
  25. std::string,
  26. bool(*)(const std::string&, const std::string&)>
  27. my_map(case_insensitive_string_cmp);
  28.  
  29. my_map["Helloooo"] = "foo";
  30. my_map["HELLOOOO"] = "bar";
  31. std::cout << my_map["hellOOOO"] << std::endl;
  32. }
  33.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
bar