Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-09-21 16:09:37


From: "Peter Dimov" <pdimov_at_[hidden]>

> > > The problem is that without swap(), it's not possible to implement a
> > > copyable class with a scoped_ptr member. With swap(), it's trivial.
> >
> > Huh?
> >
> > struct body {};
> > struct handle {
> > scoped_ptr<body> impl;
> > handle() : impl(new body) {}
> > handle(handle const& rhs)
> > : impl(new body(*rhs.get())) {}
> > };
> >
> > Maybe you meant s/assignable/copyable/?
>
> Maybe. These emails are almost a year old. :-)

Furthermore:

        handle& operator=(handle const& rhs)
        {
            impl.reset(new body(*rhs.impl));
        }

It even gives the strong guarantee.
What /is/ the rationale for swap?
I think it's for nothrow swappability of the handle class.
That's the only thing it seems to make possible.

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com


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