|
Boost : |
Subject: Re: [boost] Improving the assignment operators of various Boost types
From: David Abrahams (dave_at_[hidden])
Date: 2008-09-10 14:53:02
on Wed Sep 10 2008, Andrey Semashev <andrey.semashev-AT-gmail.com> wrote:
> One downside is that self-assignment is made suboptimal. My typical operator=
> implementation is:
>
> T& operator= (T const& that)
> {
> if (this != &that)
> T(that).swap(*this);
> return *this;
> }
>
> Not sure, however, if it is critical enough.
IMO it is not only non-critical, but the extra little bit of complexity
involved in worrying about self-assignment is slightly dangerous, and it
pessimizes the usual case (non-self-assignment) by adding a test and
branch.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk