模板参数数量错误的模板模板参数 [英] Template template parameter with wrong number of template parameters

查看:42
本文介绍了模板参数数量错误的模板模板参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑具有通过模板模板参数和两个策略定义设置的策略的模板类 C:

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 由于模板参数数量错误而不起作用.如果您指定附加模板参数的类型,是否可以使用 PolicyTwo 作为 POLICY 模板参数?

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?

我使用的是 C++03,所以别名声明不可用.我知道这个问题,但我在那里看不到解决我的问题的方法.

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;

这篇关于模板参数数量错误的模板模板参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆