Re: Template argument as rvalue reference
Le 26/10/2012 15:29, SG a =E9crit :
Am 26.10.2012 15:19, schrieb SG:
Am 26.10.2012 13:20, schrieb Juha Nieminen:
SG <sgesemann@gmail.invalid> wrote:
No, reference collapsing is always applicable. It is not restricted =
to
the case of templates.
I think it is.
Then you are wrong. Or perhaps you have a different idea about what
"reference collapsing" means.
If you have a non-templated rvalue reference parameter,
you can't give it an lvalue. You'll get a compile error.
What is an "rvalue reference parameter"?
typedef int& foo;
void bar(foo&& x);
void test() {
int a = 23;
bar(a); // actually works
}
Is x of bar an rvalue reference parameter? Well, it looks like one. Bu=
t
it is not. Due to reference collapsing x is actually an lvalue
reference.
Let me stress that this reference collapsing has nothing to do with the=
function call or the lvalue 'a' for that matter. Reference collapsing
applies because I wrote "foo&&" where foo is already a reference. The
reference collapsing rules turn foo&& into an lvalue reference as well,=
because "lvalue references win", or, to put it differently: & + && = =
&.