|
Boost : |
From: Kevin Spinar (spinarkm_at_[hidden])
Date: 2006-07-02 14:44:16
Emailed privately by Pavel Vozenilek:
> On 7/1/06, Kevin Spinar <spinarkm_at_[hidden]> wrote:
> > Is there interest in a clone_ptr class to supplement the current
smart_ptr
> > library? A clone_ptr is a smart pointer which performs a deep copy of
the
> > pointed-to object whenever the clone_ptr is copied. Also, the
polymorphic
> > type is maintained, eg:
> >
> > clone_ptr<Base> p(new Derived);
> > clone_ptr<Base> p2;
> > p2 = p; /* p and p2 now point to different Derived objects */
> >
>
> What is use case for such behaviour?
The boost.ptr_container library probably does address most of the possible
use cases for clone_ptr. In fact, a ptr_container containing only one
object could be used instead of a clone_ptr. However, a "container of one
object" would be confusing in production code. Maybe clone_ptr wouldn't be
used enough to warrant including it in Boost. Perhaps Matt Calabrese, since
he showed such enthusiasm, could provide a real-life usage for clone_ptr.
> A clone_on_write_ptr is something recognisable
> but why to clone on copy? This should be addressed.
To me it seems clone-on-copy vs clone-on-write is an optimization issue and
not a semantics issue. Considering it isn't possible to determine if someone
is merely accessing the object instead of modifying it (foo = *myptr; and
*myptr = foo; both use the same operator* and the same operator-> is used
regardless whether the member function is const) I don't believe
clone-on-write would significantly reduce the number of copies that are
made.
On 7/2/06, Matt Calabrese <rivorus_at_[hidden]> wrote:
>
> As a suggestion, if you weren't going to do so already, use the
> pointer containers' clonable concept to get the cloning functionality
> required for copies (
>
> http://boost.org/libs/ptr_container/doc/reference.html#the-clonable-concept
> ).
>
Yes, that is something I'll look into.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk