You need a little template to get the right tuple specialization from typelist , because you cannot just save the parameter package as it is.
As an example, you can do this by correctly using the function declaration and declaration of use:
#include<tuple> #include<utility> #include<type_traits> template <class... T> struct typelist {}; template<typename... T> std::tuple<T...> foo(typelist<T...>); template<typename L> using tupleFromTypelist = decltype(foo(std::declval<L>())); int main() { using tl = typelist<int, int>; tupleFromTypelist<tl> tp{0,1}; static_assert(std::is_same<tupleFromTypelist<tl>, std::tuple<int, int>>::value, "!"); }
Or a helper class similar to the one in the following example:
#include<tuple> #include<utility> #include<type_traits> template <class... T> struct typelist {}; template<typename> struct helper; template<typename... T> struct helper<typelist<T...>> { using type = std::tuple<T...>; }; int main() { using tl = typelist<int, int>; helper<tl>::type tp{0,1}; static_assert(std::is_same<helper<tl>::type, std::tuple<int, int>>::value, "!"); }
Otherwise, let the typelist expose the specialization tuple and get it directly from it:
#include<tuple> #include<utility> #include<type_traits> template <class... T> struct typelist { using tuple = std::tuple<T...>; }; int main() { using tl = typelist<int, int>; tl::tuple tp{0,1}; static_assert(std::is_same<tl::tuple, std::tuple<int, int>>::value, "!"); }
If this is the only type for which you want to use the parameter package, this is the easiest approach.
source share