【发布时间】:2016-09-28 15:21:07
【问题描述】:
鉴于以下代码,用 Boost hana 表达相同功能的合适方式是什么?
#include <type_traits>
#include <boost/hana/type.hpp>
#include <boost/hana/core/when.hpp>
namespace hana = boost::hana;
struct S {
template<
typename T,
typename = typename std::enable_if_t< (T::value) > > // <-- equivalent?
S (const T&) { }
};
struct X { static constexpr int value = 0; };
struct Y { static constexpr int value = 1; };
int main () {
S a (X { }); // <-- must fail
S b (Y { });
return 0;
}
when 的文档提到它是 enable_if 的替代品,但我不确定如何在这种情况下应用它。那么,如何使用 Boost hana 选择性地启用模板构造函数?
【问题讨论】:
-
hana::when是关于启用部分专业化。 -
@Barry:是的,我正在寻找一种(也许)聪明的方法,用一些简洁的hana咒语代替普通的 enable_if。
标签: c++ boost boost-hana