You can use the indices trick along with has_type (from here):
#include
#include
// ##############################################
// from
https://stackoverflow.com/a/25958302/678093
template
struct has_type;
template
struct has_type> : std::false_type {};
template
struct has_type> : has_type> {};
template
struct has_type> : std::true_type {};
// ##############################################
template
struct intersect
{
template
static constexpr auto make_intersection(std::index_sequence ) {
return std::tuple_cat(
std::conditional_t<
has_type<
std::tuple_element_t,
S2
>::value,
std::tuple>,
std::tuple<>
>{}...);
}
using type = decltype(make_intersection(std::make_index_sequence::value>{}));
};
struct T1{};
struct T2{};
struct T3{};
using A = std::tuple;
using B = std::tuple;
int main()
{
static_assert(std::is_same, intersect
::type>::value, "");
}
live example