std::string - case insensitive?

G

Gernot Frisch

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?
 
V

Victor Bazarov

Gernot Frisch said:
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
 
R

rajkumar

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
 
R

Richard Herring

Gernot Frisch said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top