Aug 2, 2010 at 11:21pm UTC
If the map is like
std::map<int, std::string> myMap
myMap[1]="ab"
myMap[2]="bb"
myMap[3]="ba"
I have to check if a string is present in the map or not
myMap.count() wont work..Can anyone tell me how can I for example check if "bb" exist in the map or not
Thanks
Aug 3, 2010 at 12:24pm UTC
Is there any other way as I have to use it a couple of times and its making my program really slow
Aug 3, 2010 at 1:12pm UTC
Option 1. Change it to std::map< std::string, int >.
Option 2. Use boost::multi_index_container<>.
Aug 3, 2010 at 1:13pm UTC
You could keep a parallel std::set<> with all your values in.
Aug 3, 2010 at 2:07pm UTC
I've recently become an advocate of boost::multi_index_container. It would be perfect for this.
Anyway, here are some practical thoughts about your problem:
1. First of all, unless you really need the integer key, consider just using a std::set<std::string>.
2. You could create a small predicate functor and pass it to std::find_if. Note that this would be O(n) lookup.
Last edited on Aug 3, 2010 at 2:08pm UTC