Increase ptr_map by replacing value

Given the key, I am trying to replace the value. With regular maps that don't use pointers, I just used the following call

iter->second = object; //Where object was passed in by reference 

How to achieve the same result with boost :: ptr_map? The concept here is that we replace the entire class using a derived_object

 iter->second = derived_object; //derived_object is a base_object pointer 
+4
source share
1 answer

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.

+4
source

All Articles