K
K. Frank
Hello Group!
As I understand it, an rvalue reference is not allowed to bind
to an lvalue, and I see this behavior in simple test cases.
But when the rvalue reference is part of a template, it can.
Specifically:
void f (int&& arg) {}
template<typename T> void g (T&& arg) {}
void h() {
int i;
f (i); // fails -- error: cannot bind 'int' lvalue to 'int&&'
g (i); // succeeds
}
(To be clear, the line "g (i);" compiles, but "f (i);" does not.)
Why does the rvalue-reference argument in the template function
g bind more liberally than that in the regular function f? (And
why would this difference be a good thing?)
I suppose this would have something to do with template deduction,
but I haven't been able to make any progress with the standard on
this.
Thanks for any insight.
K. Frank
As I understand it, an rvalue reference is not allowed to bind
to an lvalue, and I see this behavior in simple test cases.
But when the rvalue reference is part of a template, it can.
Specifically:
void f (int&& arg) {}
template<typename T> void g (T&& arg) {}
void h() {
int i;
f (i); // fails -- error: cannot bind 'int' lvalue to 'int&&'
g (i); // succeeds
}
(To be clear, the line "g (i);" compiles, but "f (i);" does not.)
Why does the rvalue-reference argument in the template function
g bind more liberally than that in the regular function f? (And
why would this difference be a good thing?)
I suppose this would have something to do with template deduction,
but I haven't been able to make any progress with the standard on
this.
Thanks for any insight.
K. Frank