Re: rvalue swap confusion
On 17 Apr., 00:41, Dragan Milenkovic <dra...@plusplus.rs> wrote:
Hello,
n2844 changed the behavior of references:
* Rvalue references can no longer bind to lvalues.
* One can explicitly static_cast an lvalue to an rvalue
without creating a temporary.
You mean "static_cast an lvalue to rvalue *reference* without creating
a temporary".
Yes, and this is a good thing. You need this cast for std::move and
std::forward. Apart from the arguments against the original binding
rules mentioned in related papers there's another good one: The new
rules will probably cause less confusion. Some people initially
thought && would only bind to an rvalue anyways. Also, the new rules
are more consistent w.r.t. the &&-ref qualifier for member functions.
[...]
Among other things it removes rvalue swap from std::function.
My question is how does this relate to
http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-defects.html#770
What is the final interface like? Could someone help?
I'm not sure. But a single swap member for std::function with a &&
parameter won't do it since && doesn't bind to lvalues anymore. I
honestly don't understand the motivation for #770. You can still swap
an rvalue with an lvalue by invoking the swap member function on the
rvalue. It even works in C++98:
vector<int> source();
vector<int> a;
source().swap(a);
Cheers!
SG
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]