很抱歉,如果已经回答了这个问题,但我一直在寻找几个小时,但找不到任何尝试过类似事情的人。我正在尝试做类似以下的事情,但我不知道Entity_Aspectual的语法应该是什么。
template<class Context>
class Trait1_Barsome
{
};
template<class Context>
class Trait1_Foobish
{
};
template<class Context>
class Trait2_Barsome
{
};
template<class Context>
class Trait2_Foobish
{
};
class Aspect_Foobish
{
public:
template<class Context>
using Trait1Policy = Trait1_Foobish<Context>;
template<class Context>
using Trait2Policy = Trait2_Foobish<Context>;
};
class Aspect_Barsome
{
public:
template<class Context>
using Trait1Policy = Trait1_Barsome<Context>;
template<class Context>
using Trait2Policy = Trait2_Barsome<Context>;
};
template<class Context,
template<class> class Trait1,
template<class> class Trait2>
class Entity:
public Trait1<Context>,
public Trait2<Context>
{
};
class ActualContext {};
template<class Context,
class Aspect>
using Entity_Aspectual = Entity<Context,
typename Aspect::Trait1Policy,
typename Aspect::Trait2Policy>;
int main()
{
Entity_Aspectual<ActualContext, Aspect_Foobish> foobishEntity;
Entity_Aspectual<ActualContext, Aspect_Barsome> barsomeEntity;
return 0;
}
在这种情况下似乎微不足道,但在我的应用程序中,您在Entity中看到的特化类型要复杂得多,如果我尝试了类似以下的解决方案,会使Entity_Aspectual非常冗长:
template<class Trait1,
class Trait2>
class Entity:
public Trait1,
public Trait2
{
};
template<class Context,
class Aspect>
using Entity_Aspectual = Entity<typename Aspect::template Trait1Policy<Context>,
typename Aspect::template Trait2Policy<Context>>;