|
Boost : |
From: David Abrahams (abrahams_at_[hidden])
Date: 2001-05-18 11:45:47
----- Original Message -----
From: "Gary Powell" <Gary.Powell_at_[hidden]>
> Also, while I can see that it would not generate the most efficient
code,
> I have a tendency to write templated assignment operators as
>
> octonion temp(a_affecter);
> using std::swap;
> swap(temp, *this);
> return this;
>
> which is exception safe, but makes an extra temporary copy.
The other way is exception-safe also. People always mistakenly associate
exception-safety with the strong guarantee. In many cases the strong
guarantee is neither sufficient nor often even neccessary for writing
exception-safe programs. The most we should say about the above method is
that it "gives stronger exception-safety guarantees than the other way,
assuming swap is non-throwing".
Before suggesting that all assignments should be written that way by default
it is worth considering whether the strong guarantee will pay off for the
class in question.
-Dave
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk