[ptr_container] Does ptr_map delete objects if inserting fails?

struct foo { };
boost::ptr_map

On Mon, 24 Sep 2007 11:06:06 +0300, Thorsten Ottosen
Boris skrev:
struct foo { }; boost::ptr_map
bar; bar.insert(1, new foo()); bar.insert(1, new foo()); Does this code leak? Or does bar delete the second instance of foo?
The containers never leak. (If so, it is a bug).
I asked as it wasn't clear to me if the container takes responsibility for deleting the second instance as after all it isn't stored in the container. I understand now that the code is safe though. Thanks for your reply! Boris

Boris skrev:
On Mon, 24 Sep 2007 11:06:06 +0300, Thorsten Ottosen
wrote: Boris skrev:
struct foo { }; boost::ptr_map
bar; bar.insert(1, new foo()); bar.insert(1, new foo()); Does this code leak? Or does bar delete the second instance of foo? The containers never leak. (If so, it is a bug).
I asked as it wasn't clear to me if the container takes responsibility for deleting the second instance as after all it isn't stored in the container. I understand now that the code is safe though. Thanks for your reply!
http://www.boost.org/libs/ptr_container/doc/ptr_multimap_adapter.html#modifi... in particular: "Effects: Takes ownership of x and returns an iterator pointing to it." -Thorsten

On Mon, 24 Sep 2007 17:05:18 +0300, Thorsten Ottosen
[...]
I asked as it wasn't clear to me if the container takes responsibility for deleting the second instance as after all it isn't stored in the container. I understand now that the code is safe though. Thanks for your reply!
http://www.boost.org/libs/ptr_container/doc/ptr_multimap_adapter.html#modifi...
in particular:
"Effects: Takes ownership of x and returns an iterator pointing to it."
I wasn't sure if this applies to a successful insertion only and decided to ask here before risking a memory leak. :) Boris
participants (2)
-
Boris
-
Thorsten Ottosen