Variadic template partial specialization of a class to restrict type of template arguments

Viewed 802

I have a class Foo that needs to have a variable number of template arguments, but these arguments need to be of a certain generic type, as opposed to being completely arbitrary. E.g

template < int I, typename T> struct Arg;
using type1 = Foo<Arg<3, double>>;
using type2 = Foo<Arg<1, int>, Arg<7, float>, Arg<1, int>>;

I am wondering what would be the best way to achieve this. I guess I need to start first with a plain variadic template

template < typename ...T >
class Foo;

From there, I could follow the recursive road

template < int I, typename T, typename ...Others>
template Foo<Arg<I, T>, Others...>
{
    ...
};

but the reading of this answer to another question left me wonder about my knowledge of variadic templates and how recursion can sometimes be avoided.

My question is, does the fact that the template arguments are expected to be in a relatively rigid format enable a partial specialization of Foo that would not be recursive, and that would effectively handle all Foos of the form Foo<Arg<...>,Arg<...>,...>?

2 Answers
Related