微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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是模式(在此上下文中是一个标识符).

原文地址:https://www.jb51.cc/c/112759.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐