我正在尝试在 C++11 中实现一个功能来检查所有非模板布尔参数是否为 true。举个例子吧
static_assert(all_true<true, true, true>::value) // should pass
static_assert(all_true<true, false, true>::value) // should fail
这是我的工作尝试
template <bool b>
struct bool_type : std::false_type {};
template <>
struct bool_type<true> : std::true_type {};
template <bool val, bool... vals>
struct all_true : bool_type<bool_type<val>::value && all_true<vals...>::value> {};
template <>
struct all_true<true> : bool_type<true> {};
template <>
struct all_true<false> : bool_type<false> {};
如您所见,它需要额外的结构 bool_type (具有专业化)和 are_true (也具有专业化)。你有什么办法可以简化我的代码吗?预先感谢您的回复。