It searches the entire map, caching is not performed - or at least the standard does not provide any credentials, and I would say that it does not do any implementation, because all clients of such an implementation will have to pay for possibly unwanted service data for updating cached information after each insert / delete.
The first approach is an idiomatic way to determine if a key / value pair is in the map (just use the fact that operator -> should be used instead of operator . , Because what you get from find() is an iterator, and the assignment iter should be out of condition if ):
auto iter = map.find(key); if (iter != map.end()) { return iter->second; }
source share