superfluous constructor ?

Jonathan Wakely jwakely.gcc@gmail.com
Sun Feb 26 15:38:00 GMT 2012


On 26 February 2012 12:29, Jonathan Wakely wrote:
> On 26 February 2012 03:21, Serge Pavlovsky wrote:
>> hi
>> in <functional>
>>      function&
>>      operator=(function&& __x)
>>      {
>> function(std::move(__x)).swap(*this);
>> return *this;
>>      }
>> why not just __x.swap(*this); ?
>>
>
> That would not destroy the current contents of *this immediately.

See http://cplusplus.github.com/LWG/lwg-closed.html#675 and
http://cplusplus.github.com/LWG/lwg-closed.html#910 for discussion
regarding this point.  The target of a move operation is expected to
be "cleared" so that destructors don't run late.



More information about the Libstdc++ mailing list