I have a tuple of types encoded as
template<class... T>struct packed;
I want to unpack it later like
template<class T>struct unpack;
template<class... T>
struct unpack<packed<T...>>{
//how to define the unpacked type here?
};
So that, I can use it as
template<class Packed>
struct foo : unpack<Packed>::type...{};
Note, I do not want to unpack the elements of the tuple immediately like
template<class... T>
struct unpack<packed<T...>> : T...{};
template<class Packed>
struct foo: unpack<Packed>{};
I am interested to have elements of the tuple 'packed' to be direct base classes of 'foo' instead of indirect base classes via 'unack'. Also the elements of the type tuple are distinct non-primitive and non-final types.
To make the example more detailed,
template<class T, T... Values>
struct variadic_values{};
template<class T,T From,class Encode,T To>
struct value_gen;
template<class T, T From, T... Values, T To>
struct value_gen<T,From,variadic_values<T,Values...>,To>
{
using type = typename value_gen<T,From+1,variadic_values<T,Values...,From>,To>::type;
};
template<class T,T From,T... Values>
struct value_gen<T,From,variadic_values<T,Values...>,From>
{
using type = variadic_values<T,Values...>;
};
template<class T, T From,T To>
using values = typename value_gen<T,From,variadic_values<T>,To>::type;
template<unsigned Idx,class T>
struct node{};
template<class Idx,class... Ts>
struct unpack;
template<unsigned... Idx,class...Ts>
struct unpack<variadic_values<unsigned,Idx...>,Ts...> : node<Idx,Ts>...{};
template<class... Ts>
class foo : unpack<values<unsigned,0,sizeof...(ts)>,Ts...>{};
What I am interested to have is that foo
should be directly derived from node
s