Question: Im trying create a filtered type of a variadic template/parameter pack and also preserve ordering.

```cpp
// example what im trying to accomplish
template<typename... Args>
struct query
{
    using filtered = typename filtered<std::is_integral_v, Args...>
}

```

In this example filtered would filter all integral types eg.

```
query<int, A, B>::filtered == query<A, B>::filtered

```

How can I create a util like this or something that would achieve the same results

Answer: 
Comment by @Jarod42 has demo with working code 

```cpp
#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;
};

```

And integration with my example

```cpp

template<typename... Args>
struct query
{
    using filtered = filter<std::is_integral, std::tuple, Args...>::type
}

```
You can avoid recursion using `std::tuple_cat()`

```
#include <type_traits>
#include <tuple>

template <template <typename> class F, typename T>
std::enable_if_t<true == F<T>::value, std::tuple<>> filter ();

template <template <typename> class F, typename T>
std::enable_if_t<false == F<T>::value, std::tuple<T>> filter ();

template <typename...>
struct query;

template <typename ... Ts>
query<Ts...> deTuple (std::tuple<Ts...>);

template <template <typename> class F, typename ... Ts>
struct filtered
 { using type = decltype(std::tuple_cat(filter<F, Ts>()...)); };

template<typename... Args>
struct query
{
    using filtered = decltype(deTuple(std::declval<
      typename filtered<std::is_integral, Args...>::type>()));
};

class A {};
class B {};

int main ()
 {
   using T1 = typename query<int, A, B>::filtered;
   using T2 = query<A, B>;

   static_assert( std::is_same_v<T1, T2> );
 }

```