I speculated when the compiler determines that a particular function argument is an rvalue reference, and when it defines it as an lvalue reference.
I assume you are talking about function templates with universal reference parameters , eg:
template<typename T> void foo(T&& t) { }
The rules are very simple. If the argument is an rvalue of type X , then T will be output as X , so T&& means X&& . If the argument is an lvalue of type X , then T will be output as X& , so T&& means X& && , which is collapsed into X& .
If you really asked about the arguments , then the question does not make much sense because the arguments never refer to references or references to rvalue, because an expression of type X& immediately converted to an expression of type X , which denotes a reference object.
But if you really meant "How does the compiler distinguish between lvalue arguments and rvalue arguments?" (note the missing link ), then the answer is simple: the compiler knows the category of values ββfor each expression, because the standard defines for each conceivable expression what its category of values ββis. For example, a function call is an expression that can belong to one of three categories of values:
X foo();
(Provided, of course, that X itself is not a reference type.)
If this does not answer your question, clarify this question. In addition, several answers to frequently asked questions .
source share