forked from codenuri/TEMPLATE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypelist2.cpp
43 lines (23 loc) · 854 Bytes
/
Typelist2.cpp
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
#include <iostream>
using namespace std;
// Step2. NullType 과 매크로 도입
// Typelist : 타입을 여러개 보관하는 type의 list(값이 아님.)
template<typename T, typename U> struct Typelist
{
typedef T Head;
typedef U Tail;
};
struct NullType {};
// 매크로 도입
#define TYPELIST_1(T1) Typelist<T1, NullType>
#define TYPELIST_2(T1, T2) Typelist<T1, Typelist<T2, NullType>>
#define TYPELIST_3(T1, T2, T3) Typelist<T1, Typelist<T2, Typelist<T3, NullType>>>
#define TYPELIST_4(T1, T2, T3, T4) Typelist<T1, Typelist<T2, Typelist<T3, Typelist<T4, NullType>>>>
int main()
{
Typelist<int, NullType> t1;
Typelist<int, Typelist<double, NullType>> t2;
//Typelist<int, Typelist<double, Typelist<char, NullType>>> t3;
TYPELIST_1(int) t4; //
TYPELIST_4(int, double, char, short) t4; //
}