14.5.3 [temp.variadic], paragraph 5
For the purpose of determining whether a parameter pack satisfies a rule regarding entities other than parameter packs, the parameter pack is considered to be the entity that would result from an instantiation of the pattern in which it appears. [Example:
template<class ... Types> void f(Types ... rest); template<class ... Types> void g(Types ... rest) { f(&rest ...); // “&rest ...” is a pack expansion; “&rest” is its pattern }
—end example]
委员会将实体的标题赋予参数包,这样lambda表达式就可以找到它的标识符而无需明确捕获它——参见this .话虽如此,我希望看到一个与使用参数包的 lambda 表达式相关的示例,但实际情况与我的预期相去甚远。我看不出上面的示例与措辞有何关系(我认为它应该与名称查找或其他内容有关)。此外,“实体”旁边的粗体文字的目的是什么(我几乎不明白它的意思......)?
最佳答案
我认为这是标准中的一个[小]编辑问题(我提交了一个关于它的问题)。有问题的文本是核心问题 1662 的结果, 建议在第 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 [...]
— In a template parameter pack [...]
[...]
— In a fold-expression [...]
For the purpose of determining whether a parameter pack satisfies a rule regarding entities other than parameter packs, the parameter pack is considered to be the entity that would result from an instantiation of the pattern in which it appears.[Example:template<class ... Types> void f(Types ... rest); template<class ... Types> void g(Types ... rest) { f(&rest ...); // “&rest ...” is a pack expansion; “&rest” is its pattern }
-end example]
这里的例子只是一个包扩展的例子——这是上一段介绍的术语。事实上,“For the purpose of...”部分已经成为自己的段落,而不是第 4 段的扩展,这使得示例的位置非常奇怪。
也就是说,示例无论如何都不是规范的,重要的是文本。
关于c++ - 标准关于可变参数模板的措辞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40380203/