专业化的隐式实例化

Implicit instantiation of specialization

我无法理解为什么标准首先定义模板实例化for templates如下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.

但更进一步,它在任何地方都使用 专业化的实例化 ,如下所示 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).

我不明白。模板本身是一个不同于模板规范的概念,模板规范可以是 explicit specializationpartial specialization。例如 N3797::14.5.5/1 [temp.class.spec]:

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

我的问题是,为什么标准首先声明了模板的 instatiation 概念,但又将该概念应用于模板专业化?

此外N3797::14.7/4 [temp.spec]定义专业化概念如下:

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

那么,偏特化不是特化,对吧?我完全被这些概念搞糊涂了。你不能澄清一下吗?

这是一个类似的问题。 现在,我试着再次回答这个问题。

模板是无限类型的,所以我们不能实例化模板,我们只能实例化模板特化。

  • 隐式实例化,当前编译单元需要使用模板代码,编译器自动实例化模板特化。

  • 显式实例化,我们手动输入代码导致编译器实例化模板特化。

  • 显式特化,给定所有模板参数,并给出非泛型代码。一旦模板类型匹配,然后实例化这个特化。
  • 偏特化,部分参数给定模板,给出非泛型代码。一旦模板类型匹配,然后实例化这个特化。