Avoid finding twice the same key in the map (part 2)

Later, I found the following code:

We cannot adopt the solution of the previous post, because the call to prepare is conditioned by the absence of the key in the map and precedes the insertion of value in the map. Moreover, in case of exception thrown by prepare, the value will not be inserted in the map, and hence prepare cannot be postponed after the insertion. In order to respect the flow order without paying twice the cost of finding the position of the key in the map, one should adopt the solution described by Scott Meyer in the Item 24 of Effective STL.

With C++11, the last statement would be better:

 

This entry was posted in C++, C++11, STL. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *