Question: Is there a way to remove one of the types from type expansion?

Let's use tuple as an example,

```
void foo() {
     tuple<int, double, string> t;
     // some facility to expand except the i-th type:
     expand_except_ith<0>(t);   // returns tuple<double, string>
     expand_except_ith<1>(t);   // returns tuple<int, string>
}

```

Answer: 
Here is a short [c++14](/questions/tagged/c%2b%2b14 "show questions tagged 'c++14'") version:

```
template<std::size_t...Is>
auto indexer( std::index_sequence<Is...> ) {
  return [](auto && f) {
    return f( std::integral_constant<std::size_t, Is>{}... );
  };
}
template<std::size_t N>
auto indexer() {
  return indexer( std::make_index_sequence<N>{} );
}

template<std::size_t N, class T>
auto except_nth( T&& t ) {
  constexpr auto size = std::tuple_size< std::decay_t<T> >{};
  static_assert( N < size, "No skipping past the end" );
  auto before = indexer<N>();
  auto after = indexer< size-N-1 > ();
  return before( [&]( auto...As ) {
    return after( [&]( auto...Bs ) {
      return std::make_tuple( std::get<As>(std::forward<T>(t))..., std::get<N+1+Bs>(std::forward<T>(t))... );
    } );
  });
}

```

[Live example](http://coliru.stacked-crooked.com/a/fbc366f092b37536).

This avoids depth-N template instantiation recursion of template instantiation "volume" N^2, which is hard to do in C++11 for this problem.

`indexer` is a cute little helper that lets us expand counting parameter packs without having to write a new function.

`indexer<N>()( [&]( auto...Is ) { /* code */ } )` gives us the integers `0` through `N-1` in a pack `Is...` within `/* code */`.

We do this twice, once for the leading elements, once for the tailing. Then we wrap it all up in a single `make_tuple` call.

Note that gcc in [c++14](/questions/tagged/c%2b%2b14 "show questions tagged 'c++14'") mode needs

```
      return std::make_tuple( std::get<decltype(As){}>(std::forward<T>(t))..., std::get<N+1+decltype(Bs){}>(std::forward<T>(t))... );

```

as it won't let you call a member function with a non-constexpr object even if the function does not use `this`. clang works fine, even in [c++14](/questions/tagged/c%2b%2b14 "show questions tagged 'c++14'"). I think this was a standard ambiguity that was cleared up later.
Here is a short solution using [Boost.MP11](https://www.boost.org/doc/libs/develop/libs/mp11/doc/html/mp11.html) to erase the single type denoted by an index in the type holder class (e.g. `std::tuple`, `boost::mp11::mp_list`, etc.).

```cpp
#include <tuple>
#include <string>

#include <boost/mp11/algorithm.hpp>

template<auto N, template<class...> class TList, class... Ts>
constexpr auto expand_except_ith(TList<Ts...>) {
    static_assert(N <= sizeof...(Ts), "Index to skip must be within range of size of types");
    return boost::mp11::mp_erase_c<TList<Ts...>, N, N+1>{};
}

int main() {
    std::tuple<int, double, std::string> t;
    static_assert(std::is_same_v<std::tuple<double, std::string>, decltype(expand_except_ith<0>(t))>);  
    static_assert(std::is_same_v<std::tuple<int, std::string>, decltype(expand_except_ith<1>(t))>);
    static_assert(std::is_same_v<std::tuple<int, double>, decltype(expand_except_ith<2>(t))>); 
}

```