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:
template<int U, int V> struct PolicyTwoAdaptor {
template<class T> struct type: PolicyTwo<T, U, V> { }; };
C<int, PolicyTwoAdaptor<1, 2>::type> mc2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With