gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:14:55 25 4
gpt4 key购买 nike

引入了 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com