Boost logo

Boost :

Subject: Re: [boost] [smart_ptr] copyable_ptr?
From: Christian Schladetsch (christian.schladetsch_at_[hidden])
Date: 2009-07-16 18:11:21


I have a work-in-progress Cloneable proposal here http://tinyurl.com/ndy5n8.
>From the documentation:

Motivation

We still use object type hierarchies, and we often use them with containers.
However, doing so often means that we lose value semantics for those
containers, becuase they typically contain base pointers. We would like to
have the ability to copy containers of base pointers and maintain value
semantics, and also to safely clone and query individual object instances.

Description

The Boost.Cloneable library provides a means for creating, duplicating, and
querying instances of object types that are specified in class hierarchies,
and a set of containers for those objects.

Cloneable objects can create clones of derived types from base types, can do
so given any STL-compliant allocator, and supports multiple clone type
targets.

The user of the library is able to override the default cloning process, and
may supply custom allocators. Cloneable types can derive from other
cloneable types, in which case the user can specify which subobject type to
duplicate or create when making a new clone or new object from an existing
instance.

You can use Boost.Cloneable with existing, external types without
modification to those types by using the supplied adaptor mechanism.
Boost.Cloneable also supports types that are not default-constructable.

There is a fundamental requirement that a common base class type is shared
for each type in a given class hierarchy. The user can supply their own base
classes, or sensible defaults are generated.

Key features of the library:

* Can make any class-type Cloneable with or without modification to its
definition
* Optional user-supplied base classes
* Base types can be queried for the interfaces they support
* Clones can be created from base types
* Supports multiple inheritance, cloning of sub-objects
* Supports types with no default constructors
* Customisation of the cloning process
* Support for custom allocators
* A set of heterogenous containers with emplace semantics for object
insertion

The complete source code for the library, with unit-tests, are available in
the Boost SVN respository here http://tinyurl.com/nnj7kd

Note that this is still a work in progress... I mention it here because it
intends to solve the issue raised by the original poster.

Regards,
Christian.

On Fri, Jul 17, 2009 at 9:40 AM, Gottlob Frege <gottlobfrege_at_[hidden]>wrote:

> On Thu, Jul 16, 2009 at 4:46 PM, Ross Levine<ross.levine_at_[hidden]> 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?
>
> You might want to consider copy on write.
> eg
>
> http://stlab.adobe.com/classadobe_1_1version__1_1_1copy__on__write.html
> http://stlab.adobe.com/wiki/index.php/Copy_On_Write
>
> Tony
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk