Sign up ×  I'm using an stl::map to store some key with a value.
For my app, I need to to change the value of a key only if the
current value is bigger then the previous one. To do this, I
call find() to search if the key is already in the map and so to
change its value, otherwise I call insert() to store the new
key. Is there a way to do this kind of thing in an efficient
way? Or to call only insert() with a custom constraint on the
value?  share|improve this question Show some code so that I
understand what you are trying to do. –  Hindol Oct 7 '12 at
8:34 So, basically you want to do something like myMap[key] =
std::max(myMap[key], new_value)? –  Zeta Oct 7 '12 at 8:40 @Zeta
Yes, but only if the key is already stored in the map – 
user1633717 Oct 7 '12 at 8:54  3 Answers 3  As per below, one of
the insert overloads on the std::map returns a pair containing
an iterator to the node and a bool. The bool tells you whether
the insert was successful, or there was a dupe. If false, just
update the value manually