Template argument deduction is done by comparing each function
template parameter type (call it
P)
that contains template-parameters that participate in template argument deduction
with the type of the corresponding argument of the call (call it
A)
as described below.

If removing references and cv-qualifiers from P gives
std::initializer_list<P′>
or P′[N]
for some P′ and N and the
argument is a non-empty initializer list ([dcl.init.list]), then deduction is
performed instead for each element of the initializer list independently,
taking P′
as separate function template parameter types P′i
and the ith initializer element as the corresponding argument.

In the P′[N] case, if N is a non-type template parameter,
N is deduced from the length of the initializer list.

Otherwise, an initializer list argument causes the
parameter to be considered a non-deduced context ([temp.deduct.type]).

For a function parameter pack that occurs at the end
of the parameter-declaration-list,
deduction is performed for each remaining argument of the call,
taking the type P
of the declarator-id of the function parameter pack
as the corresponding function template parameter type.

Each deduction deduces template arguments for subsequent positions in
the template parameter packs expanded by the function parameter pack.

When a function parameter pack appears in a non-deduced
context ([temp.deduct.type]), the type of that pack is
never deduced.

If
P
is a class and
P
has the form
simple-template-id,
then
the transformed A
can be a derived class D of the
deduced
A.

Likewise, if
P
is a pointer to a class of the form
simple-template-id,
the transformed A
can be a pointer to a
derived class D pointed to by the deduced
A.

However, if there is a class C that is
a (direct or indirect) base class of D and
derived (directly or indirectly) from a class B and
that would be a valid deduced A,
the deduced A cannot be B or pointer to B,
respectively.

If a
template-parameter
is not used in any of the function parameters of a function template,
or is used only in a non-deduced context, its corresponding
template-argument
cannot be deduced from a function call and the
template-argument
must be explicitly specified.

If the argument is an overload set (not containing function templates), trial
argument deduction is attempted using each of the members of the set. If
deduction succeeds for only one of the overload set members, that member is
used as the argument value for the deduction. If deduction succeeds for more than
one member of the overload set the parameter is treated as a non-deduced context.

// Only one function of an overload set matches the call so the function parameter is a deduced context.template<class T>int f(T (*p)(T));
int g(int);
int g(char);
int i = f(g); // calls f(int (*)(int))

If deduction succeeds for all parameters that contain
template-parameters that participate in template argument
deduction, and all template arguments are explicitly specified, deduced,
or obtained from default template arguments, remaining parameters are then
compared with the corresponding arguments.

For each remaining parameter
P with a type that was non-dependent before substitution of any
explicitly-specified template arguments, if the corresponding argument
A cannot be implicitly converted to P, deduction fails.

Parameters with dependent types in which no template-parameters
participate in template argument deduction, and parameters that became
non-dependent due to substitution of explicitly-specified template arguments,
will be checked during overload resolution.