   Determining if a specific key is in a map
  is there a simple way to determine if a given key is being utilized in a map?currently i'm doingvoid RemoveElement(std::string key){if(eMap[key]){  //delete object and erase from map   }else{   //do nothing}however when the if condition is ran, it will push a new element onto the map with the test key and null for the element, then jump to the else statement and do nothing.   
map<string,value*>::iterator it = map.find( key );if ( it != map.end() ) {// founddelete it->second;map.erase( it );} else {// not-found};  You will find the answer here.[wink]   ;  thanks for the replies. since both of the functions, find and count, have a complexity that is logarithmic in size, it would be safe to assume the count version would be slightly faster due to not having to call the map.end()?   ;Quote:Original post by Denzinthanks for the replies. since both of the functions, find and count, have a complexity that is logarithmic in size, it would be safe to assume the count version would be slightly faster due to not having to call the map.end()?No. Because you still have to find the iterator to erase from. The standard method for what you're trying to accomplish is as _fastcall mentioned. The call to end is constant time (it KNOWS which element is the end element).   ;  You can also just use erase.If you are using pointers then find is the best way.Stupid me for not seeing this before.   ;Quote:Original post by Denzinis there a simple way to determine if a given key is being utilized in a map?Yes. It's called .find().However, you should not have to 'delete' the value. Instead, store instances of a smart-pointer class rather than raw pointers.Quote:however when the if condition is ran, it will push a new element onto the map with the test key and null for the element, then jump to the else statement and do nothing.Interestingly, this offers another solution to your problem: 'delete' called on a null pointer is safe and does nothing, so you could look the element up with operator[] as you do, and then unconditionally delete and remove it.By the way, you should be passing std::string arguments by const reference rather than by value. It's a simple and idiomatic optimization.