Boost logo

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 <> 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

Dave Abrahams
BoostPro Computing

Boost list run by bdawes at, gregod at, cpdaniel at, john at