I have a following up question regarding this one:
Notation P and A refer to the section temp.deduct.call
If I understand template argument deduction correctly, the following happens for the code below:
template<typename T>
void foo(const T& a);
int b;
foo(std::move(b));
- First the compiler deduces two types
PandAfor the parameter declaration and the template argument, respectively. We are deducing for the case when the declaration is a referenceconst T&(but not a forwarding reference) - For
A:std::move(b)has typeint&&[xvalue] -> which is adjusted toA:= int([7.2.2#1]) - For
P:const T&-> remove const and reference ([12.9.2.1#3]) ->P:= T - Pattern Match
AagainstP-> ResultT:= int.
Two Questions:
- Is that described procedure accurate?
std::move(b)is an expression and I always thought its type isint&&(becausestd::movereturns aint&&), but ([7.2.2#1]) tells something different, meaning removing every reference before any analysis happens, so when one talks about the type of an expression, there is never any reference involved:
struct A{ A& operator+(const A&);}
A a, b;
auto c = a + b;
So a+b clearly returns a A&. but the type of the expression is A. Is that correct ? declval(a+b) is another beast, and returns A&.