vendredi 28 septembre 2018

unpacking variadic template arguments to define new template arguments

I am new to template programming and I have two questions...Hopefully someone can help me. I am trying to use variadic templates to generate a new input to another variadic template. In other words, I have a class

template <std::size_t N, std::size_t... M>
class Class1 {

}

I want to use the integer values represented by N,M to generate a new set of std::bitset type inputs to another templated class

template <typename T, typename... Ts>
class Class2 {

}

So for example if I use Class1<10,20,25> I want inside the body of Class1 to create a Class2<std::bitset<10>, std::bitset<20>, std::bitset<25>> variable. Is there a simple way to do this using C++11?

My second question then is how can I abstract this even more so that the unpacking is not specific to the std::bitset class? Is there a way to modify the Class1 template definition so that I can expand some arbitrary templated class that I develop instead of std::bitset?

Aucun commentaire:

Enregistrer un commentaire