Template arguments can be specified when referring to a function
template specialization that is not a specialization of a constructor template
by qualifying the function template
name with the list of
template-arguments
in the same way as
template-arguments
are specified in uses of a class template specialization.
A trailing template parameter pack ([temp.variadic]) not otherwise deduced will be
deduced as an empty sequence of template arguments.
— end note]
If all of the template arguments can be
deduced or obtained from default template-arguments,
they may all be omitted;
in this case, the empty template argument list <>
itself may also be omitted.
[Example 2: template<class X, class Y> X f(Y);
template<class X, class Y, class... Z> X g(Y);
void h(){int i = f<int>(5.6); // Y deduced as doubleint j = f(5.6); // error: X cannot be deduced
f<void>(f<int, bool>); // Y for outer f deduced as int (*)(bool)
f<void>(f<int>); // error: f<int> does not denote a single function template specializationint k = g<int>(5.6); // Y deduced as double; Z deduced as an empty sequence
f<void>(g<int, bool>); // Y for outer f deduced as int (*)(bool),// Z deduced as an empty sequence} — end example]
An empty template argument list can be used to indicate that a given
use refers to a specialization of a function template even when a
non-template function ([dcl.fct]) is visible that would otherwise be used.
For example:
template<class T>int f(T); // #1int f(int); // #2int k = f(1); // uses #2int l = f<>(1); // uses #1
[Example 3: template<class X, class Y, class Z> X f(Y,Z);
template<class... Args>void f2();
void g(){
f<int,constchar*,double>("aa",3.0);
f<int,constchar*>("aa",3.0); // Z deduced as double
f<int>("aa",3.0); // Y deduced as const char*; Z deduced as double
f("aa",3.0); // error: X cannot be deduced
f2<char, short, int, long>(); // OK} — end example]
Implicit conversions ([conv]) will be performed on a function argument
to convert it to the type of the corresponding function parameter if
the parameter type contains no template parameters
that participate in template argument deduction.
Because the explicit template argument list follows the function
template name, and because
constructor templates ([class.ctor]) are named without using a
function name ([class.qual]), there is no way to provide an explicit
template argument list for these function templates.
Template argument deduction can extend the sequence of template
arguments corresponding to a template parameter pack, even when the
sequence contains explicitly specified template arguments.
[Example 4: template<class... Types>void f(Types ... values);
void g(){
f<int*, float*>(0, 0, 0); // Types deduced as the sequence int*, float*, int} — end example]