On 09-10-2014 22:23, Joaquin M Lopez Munoz wrote:
Thorsten Ottosen
writes:
Just took a quick look. I would prefer if you used scoped_ptr inside poly_holder.
Hi Thorsten,
poly_holder has a very different semantics than scoped_ptr's:
1. Constructing from a const Base& does not involve heap allocation. 2. Copying involves either heap allocation and cloning if the copied elements didn't allocate, or ownership transfer otherwise.
Ok, so pick any smart pointer that allows you to do what you want, e.g. unique_ptr with a custom deleter. I'm just looking at the code and thinking there's some potential for exception-safety issues which would probably not be the case if the pointer was stored differently. Also, I can't figure our the invariant. The pointer can be null, in which case a call to delete is expensive (unique_ptr would handle this automatically). regards -Thorsten