放置参数包运算符的规则是什么

时间:2018-09-09 02:02:37

标签: c++ c++11 templates

我试图了解如何在C ++中使用参数包,我举了一些例子,让我感到困惑的是包运算符...的位置,有时是在包名之前,有时是之后:

template<typename... Ts> void func(Ts... args){
    const int size = sizeof...(args) + 2;  // <====== before
    int res[size] = {1,args...,2};   // <====== after
    // since initializer lists guarantee sequencing, this can be used to
    // call a function on each element of a pack, in order:
    int dummy[sizeof...(Ts)] = { (std::cout << args, 0)... };
}

有时在括号内,有时在括号内:

Class c1(&args...);
::new((void *)p) U(std::forward<Args>(args)...) // <==== outside

包装使用是否有一般规则?

0 个答案:

没有答案