template
void F(T&& x) {}
If we call it with argument of type int& everything is clear - reference collapsing takes pla
Forwarding references deduce lvalue reference for lvalues and rvalue reference for rvalues. For example, even for lvalue of type int&&
it will still deduce int&
(as it would for lvalue of type int
), likewise, for rvalues of type int
or int&&
it will deduce int&&
:
template
class show;
template
void F(T&& x)
{ show();}
int main() {
int&& x = 5;
F(x);
}
main.cpp:6:3: error: implicit instantiation of undefined template 'show
'
int main() {
F(5);
}
main.cpp:6:3: error: implicit instantiation of undefined template 'show
'
int main() {
int x = 5;
F(x);
}
main.cpp:6:3: error: implicit instantiation of undefined template 'show
'
int main() {
F([]()->int{return 5;}());
}
main.cpp:6:3: error: implicit instantiation of undefined template 'show
'