|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-01-08 08:39:33
Joe Gottman wrote:
>
> One major use for unique() is copy-on-write. The code would look
> something like:
>
> void write_to(shared_ptr<Foo> p, const Foo &newValue)
You mean "shared_ptr<Foo> & p", right?
> { // For simplicity, assume p.get() != 0
> if (p.unique()) {
> *p = newValue;
> } else {
> p.reset(new Foo(newValue));
> }
> }
>
> Under the current definition of unique(), this code is impossible to
> make thread-safe if weak_ptrs might exist.
True... On the other hand, copy on write classes typically do not expose the
shared_ptr<Foo> to the world, so the current unique() is enough.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk