2
votes

I can't understand why the standard first defines template instantiation for templates as follows N3797::14.7/4 [temp.spec]:

The act of instantiating a function, a class, a member of a class template or a member template is referred to as template instantiation.

But further everywhere it uses the instatiation of the specialization, like the following N3797::14.7/4 [temp.spec]:

An instantiated template specialization can be either implicitly instantiated (14.7.1) for a given argument list or be explicitly instantiated (14.7.2).

I don't understand that. A template itself is a different concept than the template specilization, which could be an explicit specialization or a partial specialization. For instance N3797::14.5.5/1 [temp.class.spec]:

The primary template shall be declared before any specializations of that template.

My question is about why the Standard first declare the instatiation concept for templates, but further it applies that concept for template specializations?

Moreover N3797::14.7/4 [temp.spec] defines the specialization concept as follows:

A specialization is a class, function, or class member that is either instantiated or explicitly specialized (14.7.3).

So, the partial specialization is not a specialization, is it? I'm totally confused by those concepts. Couldn't you clarify it a bit?

1

1 Answers

0
votes

This is a similar question here. And now,I try to answer this question again.

A template is a type of infinite, so we can not instantiate a template, we can only be instantiated template specialization.

  • Implicitly instantiated, the current compilation unit requires the use of the template code, the compiler automatically instantiated template specialization.

  • Explicitly instantiated, we manually enter the code causes the compiler to instantiate a template specialization.

  • explicit specialization, given all the template parameters, and gives a non-generic code. Once the template type match, then instantiate this specialization.
  • Partial specialization, some parameters are given template and gives a non-generic code. Once the template type match, then instantiate this specialization.