Subject: Re: [boost] Improving the assignment operators of various Boost types
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2008-09-09 19:28:36


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