我有一个编码为的类型元组
template<class... T>struct packed;
我想稍后打开它
template<class T>struct unpack;
template<class... T>
struct unpack<packed<T...>>{
//how to define the unpacked type here?
};
这样,我可以将其用作
template<class Packed>
struct foo : unpack<Packed>::type...{};
注意,我不想立即解包元组的元素
template<class... T>
struct unpack<packed<T...>> : T...{};
template<class Packed>
struct foo: unpack<Packed>{};
我有兴趣将元组“打包”的元素作为“foo”的直接基类,而不是通过“unack”的间接基类。类型元组的元素也是不同的非原始类型和非最终类型。
为了使示例更详细,
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...>{};
我感兴趣的是foo
应该直接从node
s