I am reading https://en.cppreference.com/w/cpp/language/template_argument_deduction, the definition of P and A is
Template argument deduction attempts to determine template arguments
(types for type template parameters Ti, templates for template
template parameters TTi, and values for non-type template parameters
Ii), which can be substituted into each parameter P to produce the
type deduced A
and in this page we have
If P is an rvalue reference to a cv-unqualified template parameter (so-called forwarding references), and the corresponding function call argument is an lvalue, the type lvalue reference to A is used in place of A for deduction (Note: this is the basis for the action of std::forward. Note: in class template argument deduction, template parameter of a class template is never a forwarding reference(since C++17)):
template<class T>
int f(T&&); // P is an rvalue reference to cv-unqualified T (forwarding reference)
template<class T>
int g(const T&&); // P is an rvalue reference to cv-qualified T (not special)
int main()
{
int i;
int n1 = f(i); // argument is lvalue: calls f<int&>(int&) (special case)
int n2 = f(0); // argument is not lvalue: calls f<int>(int&&)
// int n3 = g(i); // error: deduces to g<int>(const int&&), which
// cannot bind an rvalue reference to an lvalue
}
in int n2 = f(0)
, when we substitute the template argument into the pattern, we get P=T&&, and 0 is a literal, so A is a rvalue, so how we deduce that T is int?
1