如何将两个参数包一起使用?

use*_*020 8 c++ variadic-templates c++11

例如,我有一个带有两个参数包的代码

template<class... Ts, int... Is>
struct B
{

};

int main()
{
    B<int, double, 0, 1> b; // compile error here
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

任何方式获得是对的?

Naw*_*waz 6

这是不允许的.但是,你可以这样做:

template<typename ...> struct typelist {};

template<typename TypeList, int... Is>
struct B;                                //primary template. Only declaration!

template<typename ... Ts, int ... Is>
struct B<typelist<Ts...>, Is...>         //partial specialization
{
    //here you know Ts... and Is... Use them!
};

int main()
{
    B<typelist<int, double>, 0, 1> b; 
    return 0;
}
Run Code Online (Sandbox Code Playgroud)