template <typename X, typename Y> class A {
// Use Y::Q, a useful property, not used for specialization.
};
enum Property {P1,P2};
template <Property P> class B {};
class C {};
有没有办法定义这样的部分专业化,A
这A<C, B<P1> >
将是A
正常的模板,但A<C, B<P2> >
会是专业化吗?
针对 Marcelo 进行编辑:更具体地说,不应仅使用 B 选择专业化,还应选择具有特定属性的任何类型,例如它是第一个参数为 P2 的模板。
目标是为Y
提供一个漂亮的界面A
,允许编写类似A<C, Y<P2,Q> >
.
用模板模板参数替换Y
模板参数会很好,但是有没有办法在此基础上对其进行部分专门化P
?
目的是编写如下内容:
template <typename X, template <Property P> typename Y> class A {};
template <typename X> class A<X,template<> Y<P2> > {}; // <-- not valid
编辑以回应 In silico:我说制作模板模板参数会很好Y
,但实际上这违背了我想要做的目的,即用于Y
将逻辑链接的属性组合在一起,但仍然A
基于一个那些子属性。
有没有办法通过将特征添加到专业化template <> class B<P2>
然后在中使用 SFINAE A
?目的是编写如下内容:
template <> class B<P2> {
typedef int IAmP2;
};
// The following is not valid because it's a simple redefinition.
template <typename X, typename Y> class A {
// Substitution using this template would fail for Y<P1>, and only the
// general template would be left for selection.
typename Y::IAmP2 skipIfNotP2;
};