C++可变参数模板

template<class... T>
void f(T... args){
    cout << sizeof...(args) << endl;
}

sizeof...一整个是运算符
可以通过递归或逗号表达式方式展开该参数包

可以使用这种可变参数模板初始化一个可变长的数组
使用 int arr[] = {args...};
args将会展开成数组

posted @ 2023-01-26 21:43  ecnu_lxz  阅读(28)  评论(0编辑  收藏  举报