0
給定以下代碼,使用Boost hana表達相同功能的適當方式是什麼?具有boost :: hana的SFINAE模板構造函數
#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
@Barry:對,我正在尋找的是一種(或許)聰明的方式,用一些簡潔的hana咒語替換普通的enable_if。 – Engineerist