The standard rule for type inference is that reference types can never be the result of deduction. Given this code,
template <class T>
void bar(T par);
bar(0);
int a;
bar(a);
int &b;
bar(b);
all 3 calls will call foo<int>
. That is, it is T
displayed on int
, but par
has a type int
.
: , (.. T&&
T
), l X
, X &
X
.
, , X
X
X &
; X &&
.
( , , ):
template <class T>
void foo(T &&par);
foo(0);
int a;
foo(a);
foo(0)
rvalue int
. int
, , T
int
( foo<int>
), par
- int &&
.
foo(a)
l int
. Forwarding int &
. T
int &
( foo<int&>
), par
- "int & &&
", int &
.