Continuing my journey into the world of variable templates , I ran into another problem.
Assuming the following class of templates:
template < typename T > struct foo {
you can partially specialize it for modifications to template templates as follows:
template < template < typename ... > class T, typename ...Args > struct foo< T< Args... > > {
In this case, foo< int > will correspond to the default implementation and foo< std::tuple< int, char > > for a specialized implementation.
However, when using several template parameters, everything becomes more complicated. For example, if we have the following class of templates
template < typename T, typename U > struct bar {};
and we want to partially specialize it, as it was done for foo , we cannot do
template < template < typename ... > class T, typename ...TArgs, template < typename ... > class U, typename ...UArgs > struct bar< T< TArgs... >, U< UArgs... > > {}; //This would correspond to the specialized version with //T=std::tuple, //TArgs=int,char //U=std::tuple, //UArgs=float bar< std::tuple< int, char >, std::tuple< float > > b;
Indeed, if I am right, we can only have one package of template parameters, and it should be located at the end of the parameter list. I understand why this is necessary in template declarations, but for a certain partial specialization of a template (for example, the example above) this should not be a problem.
Is it possible to achieve partial specialization of templates with several packages of template parameters?
Edit : now I feel stupid ... the code I gave above compiles fine (at least with gcc 4.5). I had a compilation error not because of several packages of parameters, but because of their use as parameters of member functions. In a partial specialization of bar I tried to define a member function that accepts the TArgs and UArgs :
template < template < typename ... > class T, typename ...TArgs, template < typename ... > class U, typename ...UArgs > struct bar< T< TArgs... >, U< UArgs... > > { void method( TArgs... targs, UArgs... uargs )
The gcc member function declaration gives me an error
Parameter Packagesmust be at the end of the parameter list.
As far as I can tell, the compiler should be able to determine the correct member function for a given instance of the template, for example. bar< std::tuple< int, char >, std::tuple< float > > must contain the void method( int, char, float ) member function void method( int, char, float ) . Am I doing something wrong? Or am I trying to do something that is impossible? If so, is there a good reason why this is not possible?