1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
template<class T, class U>
struct TypeList
{
typedef T Head;
typedef U Tail;
};
#define TYPELIST_01(T1) TypeList<T1,NullType>
#define TYPELIST_02(T1,T2) TypeList<T1,TYPELIST_01(T2) >
#define TYPELIST_03(T1, T2, T3) TypeList<T1,TYPELIST_02(T2, T3) >
template<class TList, template<class>class Unit>
class GenScatterHierarchy;
template<class Head, class Tail, template<class>class Unit>
class GenScatterHierarchy<TypeList<Head,Tail>, Unit > : public GenScatterHierarchy<Head, Unit>, public GenScatterHierarchy<Tail, Unit>
{
};
template<class T, template<class>class Unit>
class GenScatterHierarchy : public Unit<T>
{
};
template<template<class>class Unit>
class GenScatterHierarchy<NullType, Unit>
{};
template<class T>
struct Holder
{
T value_;
};
template<class TList, template<class> class Unit>
Unit<typename TList::Head>& SafeFieldHelper(GenScatterHierarchy<TList, Unit>& obj, Int2Type<0>)
{
GenScatterHierarchy<TList::Head, Unit>& leftbase = obj;
return leftbase;
}
template<unsigned index , class TList, template<class> class Unit>
Unit<typename TypeAt<TList,index>::Result>& SafeFieldHelper(GenScatterHierarchy<TList, Unit>& obj, Int2Type<index>)
{
GenScatterHierarchy<TList::Tail, Unit>& rightbase = obj;
return SafeFieldHelper(rightbase, Int2Type<index-1>());
}
template<unsigned index, class TList, template<class> class Unit>
Unit<typename TypeAt<TList, index>::Result>& SafeField(GenScatterHierarchy<TList, Unit>& obj)
{
return SafeFieldHelper(obj, Int2Type<index>());
}
|