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

标签 c++ terminology c++11 variadic-templates

引入了 C++11 variadic templates

template <typename... Args>
void foo(Args... params) {
    cout << sizeof...(Args) << endl;
}

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

最佳答案

部分引用 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++ - 为可变参数模板添加的新语法实体的名称是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7972263/

相关文章:

c++ - 使用TFS生成版本头文件

c++ - 在 ubuntu 16.04 中安装 Caffe 时遇到困难

scala - 纯函数式编程中的 "value"是什么?

linux - 系统调用和库调用有什么区别?

C++ 如何使用 std::bind/std::function 引用模板函数

c++ - FFMPEG RTSP 使用 libx264 流到 MPEG4/H264 文件

c++ - 如何创建 boost::unordered_map 的子类?

javascript - 在自己的行中纠正数组函数的术语

c++ - 嵌套 Lambda 函数 - 性能影响

c++ - 更改现有对象 "on the fly"的 VTBL,动态子类化