template parameter packs access Nth type and Nth element

Others have already answered that it can be done via std::tuple. If you want to access the Nth type of a parameter pack, you may find the following metafunction handy:

template<int N, typename... Ts> using NthTypeOf =
        typename std::tuple_element<N, std::tuple<Ts...>>::type;

Usage:

using ThirdType = NthTypeOf<2, Ts...>;

Leave a Comment