Subject: Re: [boost] [smart_ptr] copyable_ptr?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-07-16 19:19:07
Ross Levine wrote:
> I was wondering if boost has considered a smart pointer that is similar to
> scoped_ptr but supports deep copy semantics. This would be useful in classes
> which use the pimpl idiom, as a common way to program these classes is with
> a scoped_ptr or auto_ptr, but then a copy constructor and copy assignment
> operator needs to be defined. Herb Sutter worked on an implementation at
> http://www.gotw.ca/gotw/062.htm, so there's precedent. Is there any interest
> for this?
I believe the reason why there is no such thing in Boost is that there
is no agreement about how the copying would work, and also about how
operator= would work either.
Indeed, one could argue the most natural way to enhance those is to
layer on top of virtual functions, but virtual operator= has limitations
and the language provides no virtual copy constructor facility (and if
it did, it would need to change its allocation model anyway). Some
methods nevertheless exist, with allocation a real problem there since
it is often too tightly coupled with construction.
Another approach would be to ditch the virtual function model altogether
and use boost.any-like techniques instead, but that means additional
space overhead as well as possibly decayed type information.
I think none ever managed to satisfy everyone.