For reference collapsing, you can see this link. (It also speaks of the implementation of Std::forward () and Std::move ())
Http://thbecker.net/articles/rvalue_references/section_08.html
It is important to note that in the case of Auto-type deduction and Template-type deduction, there will be reference-stripping: (from Scott Meyers)
Note that if doing reference collapsing, reference would be stripped first:
Things get subtler when deducing the type for a variable so is itself a reference. The reference part of the type is ignored. For example, given
int x; ... int&& r1 = ten; R1 ' s type is int&& int& r2 = x; R2 ' s type is int&
The type for both and was considered to being in a call to the r1
r2
int
template f
. This reference-stripping behavior are independent of the rule that, during type deduction for universal references, lvalues T&
T
is deduced to is of type and rvalues of type, so given these calls,
f (R1); f (R2);
The deduced type for both and is r1
r2
int&
. Why? First the reference parts of r1
' s r2
and ' s types is stripped off (yielding int
in both cases), then, because each is a lvalue, each are treated as int&
during type deduction for the Universal reference parameter f
From: "Nitty gritty Detail" of Https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers)
Reference collapsing Rules, Universal Reference and the implementation of Std::forward () and Std::move ()