Boost logo

Boost :

From: Anand Shankar (anand.shankar.k_at_[hidden])
Date: 2007-03-24 17:03:45


I was thinking whether it would be meaningful to have a

template<typename T, typename Clone_policy>
class Owned_ptr { ... };


1) The Owned_ptr takes care of object ownership like other smart pointers;
 deleting the object when the Owned_ptr is destructed.

2) The assignment operator doesn't transfer the ownership rights, but
clones the object using the Clone_polcy. This allows using the
copy constructor or a virtual clone function in the class heirarchy.

3) The copy constructor works just like assignment.

The recent projects that I've worked own have benefitted from such an helper

It eases creating deep copies of complex objects;
avoids having to implement assignment operators/copy constructors
for every class.

Best regards,

Boost list run by bdawes at, gregod at, cpdaniel at, john at