Subject: Re: [boost] [smart ptr] Any interest in copy-on-write pointer for C++11?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2013-02-08 16:33:41
On 08/02/13 18:52, Ralph Tandetzky wrote:
> It wouldn't work to add the cow logic on top of a shared_ptr, when
> polymorphism is involved. Then an explicit clone() member function of
> the template type would be needed. The nice thing about the cow_ptr is
> that you can get this cloning facility non-intrusively.
I don't see how doing that while using shared_ptr is a problem.
Either you make a shared_ptr of your structure that contains your
cloning thing, or you store it separately.
Of course you'll need to change the virtual function declaration to T*
clone(T*), since the structure wouldn't contain the object anymore.
Storing it separately seems like a better idea since it avoids the
unneeded use of dynamic allocation (all derived types are the same size).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk