TypeList 的长度计算 Length

#include <cstdlib>
#include <iostream>
#include <typeinfo>
using namespace std;
class NullType;
namespace TL
{
  template<class T,class U>
  struct TypeList
  {
    typedef T head;
    typedef U tail;
  };
}
using namespace TL;
#define TYPELIST_1(T1) TypeList<T1,NullType>
#define TYPELIST_2(T1,T2) TypeList<T1,TYPELIST_1(T2)>
#define TYPELIST_3(T1,T2,T3) TypeList<T1,TYPELIST_2(T2,T3)>
typedef TypeList<char,TypeList<signed char,unsigned char> > CharList;
template<class Tlist>struct Length;
template<>struct Length<NullType>
{
  enum{value = 0};
};
template<class T,class U>
struct Length<TypeList<T,U> >
{
  enum{value = 1 + Length<U>::value};
};
int main(int argc, char *argv[])
{
    typedef TYPELIST_3(char,signed char,unsigned char) MyChar;
    cout<<"模版链表长度-----------------------------------------"<<endl;
    cout<<"MyChar 长度:"<<Length<MyChar>::value<<endl;
    type_info* intsRtti[Length<MyChar>::value];
    system("PAUSE");
    return EXIT_SUCCESS;
}

你可能感兴趣的:(struct,System,Class,include)