Как получить шаблоны шаблонов вариационного шаблона N-го типа? Напримерполучить N-го типа шаблонов шаблонов шаблонов?
template<typename... Args>
class MyClass
{
Args[0] mA; // This is wrong. How to get the type?
};
Как получить шаблоны шаблонов вариационного шаблона N-го типа? Напримерполучить N-го типа шаблонов шаблонов шаблонов?
template<typename... Args>
class MyClass
{
Args[0] mA; // This is wrong. How to get the type?
};
Вы можете использовать std::tuple
:
#include<tuple>
template<typename... Args>
class MyClass
{
typename std::tuple_element<0, std::tuple<Args...> >::type mA;
};
Если вы хотите что-то без использования std::tuple
это работает
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;
};
Чем
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;
};
версия с 'std :: tuple_element <> :: type' более удобна. – 23W
Проверьте зЬй :: кортеж реализации (u sing Inheritance mixed with Templates) – lucasmrod