This is not the default. You will need to provide your own comparator as the third argument. The following snippet will help you ...
/************************************************************************/ /* Comparator for case-insensitive comparison in STL assos. containers */ /************************************************************************/ struct ci_less : std::binary_function<std::string, std::string, bool> { // case-independent (ci) compare_less binary function struct nocase_compare : public std::binary_function<unsigned char,unsigned char,bool> { bool operator() (const unsigned char& c1, const unsigned char& c2) const { return tolower (c1) < tolower (c2); } }; bool operator() (const std::string & s1, const std::string & s2) const { return std::lexicographical_compare (s1.begin (), s1.end (), // source range s2.begin (), s2.end (), // dest range nocase_compare ()); // comparison } };
Use it as std::map< std::string, std::vector<std::string>, ci_less > myMap;
NOTE : std :: lexicographic_compare contains some minor details. Comparing strings is not always easy given the locales. See this thread on cl c ++ if interested.
UPDATE : with c ++ 11, std::binary_function deprecated and not needed, since types are inferred automatically.
struct ci_less { // case-independent (ci) compare_less binary function struct nocase_compare { bool operator() (const unsigned char& c1, const unsigned char& c2) const { return tolower (c1) < tolower (c2); } }; bool operator() (const std::string & s1, const std::string & s2) const { return std::lexicographical_compare (s1.begin (), s1.end (), // source range s2.begin (), s2.end (), // dest range nocase_compare ()); // comparison } };
Abhay Nov 26 '09 at 6:39 2009-11-26 06:39
source share