-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypeList.hh
65 lines (50 loc) · 1.45 KB
/
TypeList.hh
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
56
57
58
59
60
61
62
63
64
65
#ifndef _TYPELIST_H_
# define _TYPELIST_H_
namespace navi {
class NullType {};
template <typename H, typename T>
class TypeList {
typedef H Head;
typedef T Tail;
};
// Operations on typeList
namespace TL {
////// SIZE ///////
template<typename TL> struct Size;
template <> struct Size<NullType>
{
enum { value = 0 };
};
template <typename T, typename U>
struct Size< TypeList<T, U> > {
enum {
value = Size<U>::value + 1
};
};
/////// Get type At /////////
template<typename TL, unsigned int index, typename DTYPE = navi::NullType>
struct GetTypeAt;
template <unsigned int index, typename DTYPE>
struct GetTypeAt<NullType, index, DTYPE>
{
typedef DTYPE type;
};
template <typename T, typename U, typename DTYPE>
struct GetTypeAt< TypeList<T, U>, 0, DTYPE>
{
typedef T type;
};
template <typename T, typename U, unsigned int index, typename DTYPE>
struct GetTypeAt< TypeList<T, U>, index, DTYPE>
{
typedef typename GetTypeAt<U, index - 1, DTYPE>::type type;
};
}
# define TYPELIST_1(T1) navi::TypeList<T1, navi::NullType>
# define TYPELIST_2(T1, T2) navi::TypeList<T1, TYPELIST_1(T2)>
# define TYPELIST_3(T1, T2, T3) navi::TypeList<T1, TYPELIST_2(T2, T3)>
# define TYPELIST_4(T1, T2, T3, T4) navi::TypeList<T1, TYPELIST_3(T2, T3, T4)>
# define TYPELIST_5(T1, T2, T3, T4, T5) navi::TypeList<T1, TYPELIST_4(T2, T3, T4, T5)>
# define TYPELIST_6(T1, T2, T3, T4, T5, T6) navi::TypeList<T1, TYPELIST_5(T2, T3, T4, T5, T6)>
} // !navi
#endif /* !_TYPELIST_H_ */