If P is not a reference type: If A is a reference type, the ref-qualifier of A’s type are ignored for type deduction

StackOverflow https://stackoverflow.com/questions/20772040

  •  21-09-2022
  •  | 
  •  

Question

I'm learning template argument deduction stuff,I have read <14.8.2.1 Deducing template arguments from a function call>(C++11 draft) many times and I think that it missed a rule:
If P is not a reference type: If A is a reference type, the ref-qualifier of A’s type are ignored for type deduction.


It must be my fault, but I dont know where it is.

Was it helpful?

Solution

A is the type of the function argument. A function argument is an expression, and expressions never have reference type. Suppose you have int i;, int &r = i;. Both the expression i and the expression r just have type int, and are lvalues. Neither has type int &. There are a few situations where a name is used other than as an expression (decltype has special exceptions for specific syntactic constructs, where they aren't treated as expressions), and in that case, the distinction matters, but using an object as a function argument is not one of them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top