问题是调用引用不是constexpr的函数不是constexpr。这就是
hana::is_valid
integral_constant
-类似于包含静态constexpr布尔值的值,因此我们可以只查看返回类型。看到了吗
bool_
举个例子:
#include <boost/hana.hpp>
#include <type_traits>
namespace hana = boost::hana;
static auto has_length = hana::is_valid([](auto&& t)
-> decltype(t.Length()) { });
template <typename T>
auto foo(T const& t)
-> std::enable_if_t<decltype(has_length(t)){}, void>
// ^-- notice the return type
// is a boolean integral constant
{ }
struct mine
{
int Length() const { return 0; }
};
int main()
{
foo(mine{});
}