Search code examples
c++language-lawyertemplate-specializationtemplate-argument-deductionfunction-templates

Is deduction of multiple template arguments in an explicit specialization of a function template allowed?


The following quote from [temp.expl.spec.11]:

A trailing template-argument can be left unspecified in the template-id naming an explicit function template specialization provided it can be deduced from the function argument type.

indicates that only a single trailing template argument may be deduced. Which would make the following exemplary code incorrect:

template <typename T1, typename T2>
void f(T1, T2*);  

template<>
void f(int, double*) { }

int main()
{
    auto d = 2.0;
    f(1, &d);
}

However, the code compiles fine with GCC and Clang. Do these compilers apply some non-standard language extension, or is the deduction supported for multiple trailing arguments?

If the latter is true, why the sentence is not formed as follows?

Trailing template-arguments can be left unspecified in the template-id naming an explicit function template specialization provided they can be deduced from the function argument types.


Solution

  • The "a" at the start refers to any not to one.

    A[ny] trailing template-argument can be left unspecified in the template-id naming an explicit function template specialization provided it can be deduced from the function argument type.

    Here's a sentence that I just made up:

    A function parameter's type T is adjusted to const T before prior analysis.

    This doesn't mean that only one of the many parameters is adjusted, but every one of them; if any, since it could also be that there are no parameters.

    The "a" refers in a more general sense to any one thing.