case insensitive find on case sensitive stl map

Discussion in 'C++' started by benhoefer@gmail.com, Apr 6, 2007.

  1. Guest

    I have been searching around and have not been able to find any info
    on this. I have a unique situation where I need a case sensitive map:

    std::map<string, int> imap;

    I need to be able to run a find on this map with a case sensitive AND
    case insensitive search. I need to be able to change this dynamically
    during execution. Is this possible? Any thoughts on this? I
    understand that I can make the map case insensitive, but that is not
    what I need.
     
    , Apr 6, 2007
    #1
    1. Advertising

  2. Mark P Guest

    wrote:
    > I have been searching around and have not been able to find any info
    > on this. I have a unique situation where I need a case sensitive map:
    >
    > std::map<string, int> imap;
    >
    > I need to be able to run a find on this map with a case sensitive AND
    > case insensitive search. I need to be able to change this dynamically
    > during execution. Is this possible? Any thoughts on this? I
    > understand that I can make the map case insensitive, but that is not
    > what I need.
    >


    How about a custom comparison function which will sort such that all
    strings which differ only in case are adjacent to one another? There
    are a number of ways to achieve this.

    Then, for case insensitive search, you can use lower_bound or
    upper_bound instead of find and efficiently look at adjacent map
    elements with the same letters modulo capitalization.

    Another possibility is to use multimap instead of map but this, unlike
    the above approach, will allow multiple identical keys and you may have
    to look at all cases even for case sensitive search.

    -Mark
     
    Mark P, Apr 6, 2007
    #2
    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,817
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  2. bb
    Replies:
    4
    Views:
    593
    Juha Nieminen
    May 19, 2007
  3. kl
    Replies:
    7
    Views:
    1,291
    James Kanze
    Jan 1, 2008
  4. Stephanie

    case sensitive / insensitive string equality

    Stephanie, Oct 3, 2005, in forum: ASP General
    Replies:
    2
    Views:
    179
    Steven Burn
    Oct 3, 2005
  5. Xah Lee
    Replies:
    4
    Views:
    984
Loading...

Share This Page