case insensitive find on case sensitive stl map

B

benhoefer

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.
 
M

Mark P

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
 

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,905
Latest member
Kristy_Poole

Latest Threads

Top