9
如何编写模板或constexpr
代码,以使match
只有在Ts
包含A
的实例时才为true?将模板参数与模板类型匹配
template <std::uint32_t, int, int>
struct A;
template <typename... Ts>
struct X
{
constexpr bool match = ???;
};
如何编写模板或constexpr
代码,以使match
只有在Ts
包含A
的实例时才为true?将模板参数与模板类型匹配
template <std::uint32_t, int, int>
struct A;
template <typename... Ts>
struct X
{
constexpr bool match = ???;
};
写特质:
template<class>
struct is_A : std::false_type {};
template<std::uint32_t X, int Y, int Z>
struct is_A<A<X,Y,Z>> : std::true_type {};
然后使用它:
template <typename... Ts>
struct X
{
constexpr bool match = std::disjunction_v<is_A<Ts>...>;
};
为std::disjunction
在C++ 11的实现见cppreference。
感谢您介绍std :: disjunction :) – Arunmu