You're looking for std::disjunction
. It's specified in N4564 [meta.logical].
#include <type_traits>
template<typename T, typename... Ts>
constexpr bool contains()
{ return std::disjunction_v<std::is_same<T, Ts>...>; }
static_assert( contains<int, bool, char, int, long>());
static_assert( contains<bool, bool, char, int, long>());
static_assert( contains<long, bool, char, int, long>());
static_assert(not contains<unsigned, bool, char, int, long>());
Live demo
Or, adapted to a struct
template<typename T, typename... Ts>
struct contains : std::disjunction<std::is_same<T, Ts>...>
{};
Or, using fold expressions
template<typename T, typename... Ts>
struct contains : std::bool_constant<(std::is_same<T, Ts>{} || ...)>
{};
Live demo
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…