Boost logo

Boost :

Subject: Re: [boost] Improving the assignment operators of various Boosttypes
From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-09-09 20:03:03

Michael Marcin:
>>> T& operator=(T arg)
>>> {
>>> arg.swap(*this);
>>> return *this;
>>> }


> 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

T t;
T f();

int main()
    t = f();

the return value of f() can be constructed into 'arg', producing the
equivalent of


If, in addition, the compiler implements RVO and f() is written in an
RVO-friendly way, there will be no copies at all.

(I'm sure that this is explained well in the clc++m thread, which I
apologize for not having read.)

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