Consider a template class C with a policy set via template template parameter and two policy definitions:
template<class T> struct PolicyOne { };
template<class T, int U, int V> struct PolicyTwo { };
template<class T, template<class> class POLICY> struct C { POLICY<T> policy; };
void f()
{
C<int, PolicyOne> mc1;
C<int, PolicyTwo<1, 2> > mc2; // doesn't work this way
}
PolicyTwo
doesn't work because of wrong number of template arguments.
Is there a way to use PolicyTwo
as POLICY
template parameter if you specify the types for the additional template parameters?
I'm using C++03, so alias declarations are not available. I'm aware of this question, but I don't see a solution to my problem there.
Depending on how the policy is used, you may be able to manage with inheritance in place of alias templates:
I can't see hwo to solve this with your current mechanism, but you can reverse the way it works and it should compile fine (and even may reduce complexity by removing the class template parameter):
The basic idea is to move the type tempalte parameter out of the policy user, and give a fully instantiated policy to it instead. Then the policy provides its template type back to the policy user through a typedef (if needed).