|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-09-21 12:34:11
From: "Peter Dimov" <pdimov_at_[hidden]>
> > 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?
Sorry, I should have said:
- the importance of the strong guarantee is almost always overplayed
- it's not always neccessary
- it's not always sufficient
- copy/swap is a fairly drastic way to achieve it
- as are other equivalent hand-coded methods
Usually, you want the strong guarantee where you can get it efficiently and
conveniently (c.f. vector<>::push_back). If you go so far as to copy your
internal state just to get the strong guarantee, you're cutting off your
clients from the possibility of using a more-efficient basic-guarantee
implementation when it will suffice. Furthermore, it may not be enough.
Suppose you've gone to great lengths to make strong-guarantee operations
out of f1 and f2, and the client wants the strong guarantee for g = (f1 +
f2). Now they have to copy your entire state again and all of your extra
work to make f1 and f2 strong is wasted.
Come to think of it, this is very much like the thread-safety
locking-granularity issue.
-----------------------------------------------------------
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