By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,230 Members | 1,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,230 IT Pros & Developers. It's quick & easy.

std::string - case insensitive?

P: n/a
hi,

what would be the easiest (fastest to write) way to abbrevate from
std::string and make it case insensitive for use with std::map?
Overwrite c'tors and = operator, or overwrite <,>, and compare
functions?

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Gernot Frisch" <Me@Privacy.net> wrote...
what would be the easiest (fastest to write) way to abbrevate from
std::string and make it case insensitive for use with std::map?
Overwrite c'tors and = operator, or overwrite <,>, and compare functions?


No, the easiest would be to provide your own comparator when
constructing your map. See the third argument for the 'map' template.

std::map<std::string, MyStoredType, MyCaseInsentitiveCompare> myMap;
V
Jul 23 '05 #2

P: n/a
You dont need to over write <

map just needs you to define < operator. == > are not needed

You can pass a custom comparion operator to the map constructor in
which case it will ignore the string < operator.
Look the third argument map takes it defaults to std::less
Raj

Jul 23 '05 #3

P: n/a
In message <39*************@individual.net>, Gernot Frisch
<Me@Privacy.net> writes
hi,

what would be the easiest (fastest to write) way to abbrevate from
std::string and make it case insensitive for use with std::map?
Overwrite c'tors and = operator, or overwrite <,>, and compare
functions?

If you want a complete case-insensitive string class, rather than just a
hack for std::map, there's another approach: use std::basic_string with
an appropriate traits class.

See http://www.gotw.ca/gotw/029.htm

--
Richard Herring
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.