If this is possible, one can index into a variadic template parameter pack without recursion. However, GCC is refusing to pick up my partial specialization here:
template <int I, typename List>
struct element_impl;
template <typename... TL, int... IL, typename T, int I, typename... TR, int... IR>
struct element_impl<I, typelist<pair<TL,IL>..., pair<T,I>, pair<TR,IR>...>> {
typedef T type;
};
prog.cpp: In instantiation of ‘
element<0, typelist<int, double, char,‘:
float, long int> >
prog.cpp:52:34: instantiated from here
prog.cpp:47:79: error: invalid use of incomplete type ‘struct element_impl<0, typelist<pair<int, 0>, pair<double, 1>, pair<char, 2>, pair<float, 3>, pair<long int, 4> >‘
Is GCC buggy, or am I ignoring some limitation of variadic templates?
The spec says at 14.8.2.5p9
Your
typelist<T>unfortunately matches that pattern.