
9 Sep
2008
9 Sep
'08
11:28 p.m.
Peter Dimov wrote:
Niels Dekker:
Basically it was concluded that /if/ an assignment operator is implemented by means of copy-and-swap, it should preferably be done as follows:
T& operator=(T arg) { arg.swap(*this); return *this; }
This is well known (although the typical form is swap(arg) instead of arg.swap(*this)). It is not widely used in Boost because it creates problems with some compilers (I recall Borland being one). The "classic" form is, unsurprisingly, much better supported across the board. Things may have improved now, of course.
It also allows you to support move assignment emulation rather elegantly using the move library in the sandbox. Thanks, Michael Marcin