Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-21 12:22:24


From: "David Abrahams" <dave_at_[hidden]>
> > The principal drawbacks of using a raw pointer as a member is that it
has
> > default semantics of the "big three"
>
> Big three?

Copy constructor, assignment operator, destructor.

> > 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. :-)

> > For a discussion on using a pointer member to achieve strong exception
> > safety, see:
> >
> > http://www.gotw.ca/gotw/059.htm
>
> Uh, thanks, I think I invented that idiom. Too bad its importance is
always
> overplayed ;-/.

Well this is C++ where things are reinvented on a busy yearly schedule. :-)

BTW overplaying copy+swap is a good thing. It's difficult to make a mistake
when using copy+swap, and it's incredibly easy to make a mistake when
hand-coding. Even shared_ptr had a bug in its copy+swap-less operator= IIRC.
Or was it reset?


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