I have an object:
map<A*, string> collection;
I would like to call the map::find function, but the value I have for the key is const, like in the following code, which does not compile:
const A* a = whatever();
collection.find(a);
The following code works and performs the equivalent of the find operation:
const A* a = whatever();
map<A*, string>::iterator iter;
for(iter = collection.begin(); iter != collection.end(); ++iter)
if(iter->first == a)
break;
// iter now contains the result or map::end (just like map::find)
But it is probably not as efficient as the find member function, and it's also ugly and masks the intent of the code.
How can I call the find function?
Thanks
Edit:
I am intentionally using a pointer type for the key in the map. The behaviour I want is for the map to use pointer equality for the keys. (Just like in my loop code)