【发布时间】:2019-07-01 10:25:29
【问题描述】:
我有自己的布尔类型的定义
template<bool b>
struct Bool {
constexpr static bool value = b;
};
using True = Bool<true>;
using False = Bool<false>;
我正在尝试获取类 Eq 的 haskell Bool 实例。
template<typename T>
struct Eq {
template<typename R>
struct equal;
template<typename R>
struct notEqual {
using value = typename not_<typename equal<T, R>::value>::value;
};
};
我想知道,如何对“equal”类进行专门化。更清楚地说,我想要这样的东西:
template<bool a>
template<bool b>
struct Eq<Bool<a>>::equal<Bool<b>> {
using value = typename std::conditional<a == b, True, False>::type;
};
有解决办法吗?我试图做到这一点:
template<bool a>
struct Eq<Bool<a>>::equal<Bool<a>> {
using value = True;
};
但是编译器告诉我“'mtp::Eq<T>::equal':模板参数太多”。感谢您的帮助。
【问题讨论】:
-
注意
std::true_type、std::false_type(基于std::integral_constant)存在 -
还有
std::is_same。
标签: c++ templates metaprogramming