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:
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.
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
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
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
* 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
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.
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
> > scoped_ptr but supports deep copy semantics. This would be useful in
> > which use the pimpl idiom, as a common way to program these classes is
> > 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
> > for this?
> You might want to consider copy on write.
> Unsubscribe & other changes:
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk