@Jarod42 的评论有工作代码演示
#include <tuple>
#include <type_traits>
template<template<class> class, template<class...> class, class...>
struct filter;
template<template<class> class Pred, template<class...> class Variadic>
struct filter<Pred, Variadic>
{
using type = Variadic<>;
};
template<template<class> class Pred,
template<class...> class Variadic,
class T,
class... Ts>
struct filter<Pred, Variadic, T, Ts...>
{
template<class, class>
struct Cons;
template<class Head, class... Tail>
struct Cons<Head, Variadic<Tail...>>
{
using type = Variadic<Head, Tail...>;
};
using type = typename std::conditional<
Pred<T>::value,
typename Cons<T, typename filter<Pred, Variadic, Ts...>::type>::type,
typename filter<Pred, Variadic, Ts...>::type>::type;
};
并与我的示例集成
template<typename... Args>
struct query
{
using filtered = filter<std::is_integral, std::tuple, Args...>::type
}