c++ - Is it possible to typedef a parameter pack? -
is possible typedef parameter pack? example
template<class t, class... args> struct { typedef t type; // typedef it, derived class can use it. // how parameter packs? // option 1: typedef args arguments; // option 2: using arguments = args; // option 3: can put in tuple, how can untuple pack typedef tuple<args...> tuple; };
i want using above technique implement following
template<int... values> struct integralsequence { enum { size = sizeof...(values) }; template <unsigned i> struct @ { enum { value = typename tuple_element<i, tuple<integral_constant<int, values>...>>::type::value }; }; }; template<unsigned n> struct ascendingsequence { typedef integralsequence<ascendingsequence<n-1>::values..., n> type; using values = type::values; // if works }; template<> struct ascendingsequence<1> { typedef integralsequence<0> type; using values = type::values; // if works };
you can pack them in tuple
, or in arbitrary empty class template (i prefer call pack
):
template<typename... args> struct pack { }; template<class t, class... args> struct { using args = pack<args...>; };
if given a
e.g. in function template , want deduce args...
, can this:
template<typename... args, typename a> void f(pack<args...>, a) { /* use args... here */ } template<typename a> void f(a a) { f(typename a::args(), a); }
pack
being empty convenient in situations that. otherwise you'd need other means pass args
without passing tuple
contains data (e.g. wrapping yet empty struct).
or, in class template specialization:
template<typename t, typename = typename t::args> struct b_impl; template<typename t, typename... args> struct b_impl <t, pack<args...> > { // use args... here }; template<typename t> using b = b_impl<t>;
i guess these options of deduction , partial specialization @dyp mentioned.
edit in response edited question. ok, xy problem. if integralsequence
need, can use std::make_integer_sequence
in c++14 or check my answer question few minutes ago efficient implementation.
Comments
Post a Comment