加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 02:59:17 所属栏目:百科 来源:网络整理
导读:C 11介绍了 variadic templates template typename... Argsvoid foo(Args... params) { cout sizeof...(Args) endl;} Args和params的名字是什么?我知道其中一个(至少?)被称为可变参数模板包,但它是什么?另外叫什么? 解决方法 部分引用FDIS,§14.5.3: 1
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是模式(在此上下文中是一个标识符).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读