C++ reference collapse rules

In traditional C++, we cannot continue to reference a reference type, but C++ relaxes this practice due to the appearance of rvalue references, resulting in a reference collapse rule that allows us to reference references, which can be left-referenced, Can be quoted right again. But it follows the following rules:

Therefore, the use of T&& in the template function may not be able to make rvalue references. When an lvalue is passed in, the reference of this function will be deduced as an lvalue. More precisely, no matter what type of reference the template parameter is, if and only if the actual parameter type is a right reference, the template parameter can be deduced as a
right reference type
.
 

Guess you like

Origin blog.csdn.net/xunye_dream/article/details/114763659