This will do the trick:
the_map.replace(iter, derived_object);
Where, of course, the_map is the mapping iter points to.
Note that ptr_map<K,V>::replace returns ptr_map<K,V>::auto_type , so you can capture the replaced object if you want. Of course, if you ignore him, it is automatically destroyed, and you do not need to know that he was there.
source share