[temp.variadic]中关于包扩展实例化的措辞

The wording about instantiation of a pack expansion in [temp.variadic]

我想知道下面的引述是不是写错了,就是

temp.variadic#7

The instantiation of a pack expansion that is neither a sizeof... expression nor a fold-expression produces a list E1,E2,...En , where N is the number of elements in the pack expansion parameters. Each Ei is generated by instantiating the pattern and replacing each pack expansion parameter with its ith element. Such an element, in the context of the instantiation, is interpreted as follows:

  • if the pack is a template parameter pack, the element is a template parameter of the corresponding kind (type or non-type) designating the type or value from the template argument; otherwise,
  • if the pack is a function parameter pack, the element is an id-expression designating the function parameter that resulted from the instantiation of the pattern where the pack is declared.

函数参数包的模式是没有省略号的参数声明,因为它的定义如下:
temp.variadic#4

A pack expansion consists of a pattern and an ellipsis, the instantiation of which produces zero or more instantiations of the pattern in a list (described below). The form of the pattern depends on the context in which the expansion occurs. Pack expansions can occur in the following contexts:

  • [...]
  • In a function parameter pack ([dcl.fct]); the pattern is the parameter-declaration without the ellipsis.

通常的参数声明包括:

无论如何,decl-specifier-seq 不是可选组件。

在这个例子中

template<typename...T>
void func(T...args){
}

T...args是一个函数参数包,其中T args是它的模式。所以我的问题是,为什么从函数参数包的模式实例化生成的元素是 id-expression,但是 id-expression 只是参数声明的声明符的一部分。

在该包扩展中,T args 被扩展(即使后者被 声明 作为一个包);因此,生成的 参数声明 具有 T1 args1,T2 args2,… 的形式,并适当地配备了 decl-specifier.

我试着回答这个问题,为了理解这些句子,这些句子有必要拆分成几个部分。

  1. A function parameter pack is a function parameter that accepts zero or more function arguments.
什么是函数参数包?

在c++17标准中,它说:

dcl.fct#16

A declarator-id or abstract-declarator containing an ellipsis shall only be used in a parameter-declaration. Such a parameter-declaration is a parameter pack. When it is part of a parameter-declaration-clause, the parameter pack is a function parameter pack.

听起来像是一个parameter-declaration where declarator-id or abstract-declarator containing an ellipsis and such a parameter-declaration appear in parameter-declaration-clause, such parameter-declaration is a function parameter pack.对吧?

现在,我们看看最新的草案是怎么说的:

dcl.fct#21

A declarator-id or abstract-declarator containing an ellipsis shall only be used in a parameter-declaration. When it is part of a parameter-declaration-clause, the parameter-declaration declares a function parameter pack.

说的是parameter-declaration where declarator-id or abstract-declarator containing an ellipsis and such a parameter-declaration appears in parameter-declaration-clause, as far to here, they are the same, however, the difference在这里,这样的参数声明声明了一个函数参数包。意思是T...args声明了一个函数参数包。

  1. A pack expansion consists of a pattern and an ellipsis, the instantiation of which produces zero or more instantiations of the pattern in a list... Pack expansions can occur in the following contexts:
  • In a function parameter pack ([dcl.fct]); the pattern is the parameter-declaration without the ellipsis.

这句话的意思是包扩展发生在一个函数参数包的上下文中,模式是没有省略号的参数声明。通俗地说,对于这种情况 T...args,其中 T... 表示包扩展,T...args 的模式是 T args.

The instantiation of a pack expansion...

  1. if the pack is a function parameter pack, the element is an id-expression designating the function parameter that resulted from the instantiation of the pattern where the pack is declared.

关于第三弹,这个pack并不代表T,它是作为对第一弹的解析,通过parameter-declaration声明的东西。理解这句话的另一个要点是 函数参数,它是由声明 pack 的模式实例化产生的 ,如上所述,模式是 T args 其中 pack 是宣布。所以,强调的句子意味着 function parameter 是这些包扩展 T args 模式实例化的结果 T...args,现在它证实了第二个项目符号,对于某些情况,例如 postfix-expression(args...), 包 args 被用作这种包扩展的模式,这种包扩展的实例化将是 id-expression 指定来自模式实例化的函数参数 T args .