【发布时间】:2020-02-28 10:07:53
【问题描述】:
考虑以下几点:
enum color {
r, g, b
};
template <color T>
constexpr bool is_green = std::is_same<T, color::g>::value;
g++ 编译失败,出错
错误:
template<class, class> struct std::is_same模板参数列表中参数 1 的类型/值不匹配
使用枚举参数声明模板类显然是可以接受的
template <color foo>
class widget
但是,因此似乎也应该有某种方法来检查该值(供以后在条件中使用;static_if 本来不错,但需要 c++17)。
【问题讨论】:
-
fwiw
std::euqal_to(不要与std::equal混淆)比较值,但你不需要它