Boost logo

Boost :

Subject: Re: [boost] Improving the assignment operators of various Boosttypes
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2008-09-10 12:17:39

Peter Dimov wrote:
> Michael Marcin:
> ...
>> It also allows you to support move assignment emulation rather
>> elegantly using the move library in the sandbox.
> There is no need to use a move library. The point of the above
> assignment is to take advantage of copy elision, which allows the
> compiler to construct the rvalue argument directly into 'arg', without a
> copy. In other words, if you have

For rvalues yes but for lvalues you need move emulation. Which can be
implemented in the sandbox move library as follows.

class foo
    foo( T t );
    foo( boost::move_from<foo> other )
       swap( other.source );

    foo& operator=( foo rhs )
       swap( rhs );

    void swap();


T bar();

int main()
   foo x;
   foo y( bar() );
   x = boost::move(y);


Michael Marcin

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