std::string - case insensitive?

Discussion in 'C++' started by Gernot Frisch, Mar 17, 2005.

  1. 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);}
     
    Gernot Frisch, Mar 17, 2005
    #1
    1. Advertising

  2. "Gernot Frisch" <> 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
     
    Victor Bazarov, Mar 17, 2005
    #2
    1. Advertising

  3. Gernot Frisch

    Guest

    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
     
    , Mar 17, 2005
    #3
  4. In message <>, Gernot Frisch
    <> 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
     
    Richard Herring, Mar 18, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tee
    Replies:
    3
    Views:
    7,907
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  2. Replies:
    1
    Views:
    2,548
    Mark P
    Apr 6, 2007
  3. bb
    Replies:
    4
    Views:
    642
    Juha Nieminen
    May 19, 2007
  4. Mosfet
    Replies:
    22
    Views:
    1,780
    kwikius
    Jul 23, 2007
  5. Xah Lee
    Replies:
    4
    Views:
    1,043
Loading...

Share This Page