Folding-expressionを用いてparameter pack長のindex_sequenceを構築する
再帰深度がO(1)に抑えられる.(趣味)
#include <type_traits> template <int... Ns> struct V; template <int N, int... Ns> struct V<N, Ns...> { template <int M> V<N + 1, N, Ns...> operator +(V<M>); }; template <> struct V<> { template <int M> V<0> operator +(V<M>); }; template <typename... Types> struct S { template <int... Indices> static V<(sizeof...(Indices) - Indices - 1)...> reverse(V<Indices...>); template <typename> struct dummy {}; using type = decltype(reverse((V<>{} + ... + V<sizeof(dummy<Types>)>{}))); }; struct T; int main() { static_assert(std::is_same<V<0, 1, 2, 3, 4>, typename S<T, T, T, T, T>::type>::value); }