c – 为可变参数模板添加的新语法实体的名称是什么?

C 11介绍了 variadic templates
template <typename... Args>
void foo(Args... params) {
    cout << sizeof...(Args) << endl;
}

Args和params的名字是什么?我知道其中一个(至少?)被称为可变参数模板包,但它是什么?另外叫什么?

解决方法

部分引用Fdis,§14.5.3:

1 A template parameter pack is a template parameter that accepts zero or more template arguments.

2 A function parameter pack is a function parameter that accepts zero or more function arguments.

3 A parameter pack is either a template parameter pack or a function parameter pack.

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.

所以在你的例子中,

> typename … Args是一个模板参数包(因此也是一个参数包)> Args … params是一个函数参数包(因此也是一个参数包)> sizeof …(Args)是一个包扩展,其中Args是模式(在此上下文中是一个标识符).

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...