2013-04-11 2 views

Antwort

27

können Sie std::tuple verwenden:

#include<tuple> 

template<typename... Args> 
class MyClass 
{ 
    typename std::tuple_element<0, std::tuple<Args...> >::type mA; 
}; 
5

Wenn Sie etwas wollen, ohne std::tuple diese

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; 
}; 

als

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; 
}; 
+0

Version mit 'std :: tuple_element <> :: type" ist komfortabler. – 23W