c++ - 标准关于可变参数模板的措辞

标签 c++ language-lawyer

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/

相关文章:

c++ - 带有可变参数模板的奇怪的重复模板模式 (C++)

c++ - `std::vector<T>::clear` *真的*没有指定时间复杂度吗?

ruby 关键字参数解构

c++ - 我不明白标准中的 3.4/2

c++ - C5002 1204 自动矢量化程序原因代码是什么意思?

c++ - 如何从 POSIX 文件描述符构造 c++ fstream?

c++ - 如何在 Amazon EC2(运行 Ubuntu Lucid)上设置 Nginx 并配置 FastCGI/FastCGI C++?

c++ - 为什么 GPU 外部的顶点变换与 GPU 内部的顶点变换不同?

c++ - 这是在序列点之间对同一对象的多次访问定义明确的行为吗?

c - 使用指向 one-past-malloc 的指针是否定义明确?