Typelist定义:
template
struct Typelist
{
typedef T Head;
typedef U Tail;
};
约定为Typelist的最后一个元素 : NullType 定义class NullType {};
约定Tail可以为另一个Typelist,这样就可以无限扩充,管理任意多的类型了
MakeTypelist定义:(为18个类型以内的Typelist提供帮助,足够用了)
template
<
typename T1 = NullType, typename T2 = NullType, typename T3 = NullType,
typename T4 = NullType, typename T5 = NullType, typename T6 = NullType,
typename T7 = NullType, typename T8 = NullType, typename T9 = NullType,
typename T10 = NullType, typename T11 = NullType, typename T12 = NullType,
typename T13 = NullType, typename T14 = NullType, typename T15 = NullType,
typename T16 = NullType, typename T17 = NullType, typename T18 = NullType
>
struct MakeTypelist
{
private:
typedef typename MakeTypelist
<
T2 , T3 , T4 ,
T5 , T6 , T7 ,
T8 , T9 , T10,
T11, T12, T13,
T14, T15, T16,
T17, T18
>
::Result TailResult;
public:
typedef Typelist Result;
};
template<>
struct MakeTypelist<>
{
typedef NullType Result;
};
如下使用:
typedef MakeTypelist ::ResultIntegerTypes;
Typelist可以管理一堆型别,下篇再说下加于其上的一系列优雅的操作