How to get the Nth type of variadic template templates? For example
template<typename... Args>
class MyClass
{
Args[0] mA; // This is wrong. How to get the type?
};
You can use std::tuple
:
#include<tuple>
template<typename... Args>
class MyClass
{
typename std::tuple_element<0, std::tuple<Args...> >::type mA;
};
If you want something without using std::tuple
this works
template<std::size_t N, typename T, typename... types>
struct get_Nth_type
{
using type = typename get_Nth_type<N - 1, types...>::type;
};
template<typename T, typename... types>
struct get_Nth_type<0, T, types...>
{
using type = T;
};
Than
template<std::size_t N, typename... Args>
using get = typename get_Nth_type<N, Args...>::type;
template<typename... Args>
class MyClass
{
get<0, Args...> mA;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With