Krishanu Debnath wrote:
...
In case the key is not present, map::operator[] returns(and also insert)
a pair with that key and a default value.
Now my question is whether addition of these extra 'unwanted
key' can increase the run time for search operation. I am not sure about
the implementation.
...
Well, it probably does increase the run time. However, I don't exactly
understand your concern. 'std::map<>::operator []' is not a pure search
operation and is not intended to be used as such. 'std::map<>::operator
[]' is a search-and-overwrite operation (hence no const version, BTW).
If you need a pure search operation, use 'std::map<>::find'.
--
Best regards,
Andrey Tarasevich