
10 Sep
2008
10 Sep
'08
6:53 p.m.
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