Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use two parameter packs together?

For example I have a code as below with two parameter packs

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

};

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

Any way to get is right?

like image 803
user1899020 Avatar asked Apr 09 '14 13:04

user1899020


1 Answers

That is not allowed. You can do this, however:

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;
}
like image 119
Nawaz Avatar answered Sep 27 '22 18:09

Nawaz