Telkin
Loading...
Searching...
No Matches
Preprocessor.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef PP_CONCAT
4 #define PP_CONCAT(x, y) x ## y
5#endif
6
7#ifndef PP_CONCAT_VAL
8 #define PP_CONCAT_VAL(x, y) PP_CONCAT(x, y)
9#endif
10
11#ifndef PP_STR
12 #define PP_STR(...) #__VA_ARGS__
13#endif
14
15#ifndef PP_STR_VAL
16 #define PP_STR_VAL(...) PP_STR(__VA_ARGS__)
17#endif
18
19#ifndef PP_ARG_N
20 #define PP_ARG_N(
21 _1, _2, _3, _4, _5, _6, _7, _8, _9, _10,
22 _11, _12, _13, _14, _15, _16, _17, _18, _19, _20,
23 _21, _22, _23, _24, _25, _26, _27, _28, _29, _30,
24 _31, _32, _33, _34, _35, _36, _37, _38, _39, _40,
25 _41, _42, _43, _44, _45, _46, _47, _48, _49, _50,
26 _51, _52, _53, _54, _55, _56, _57, _58, _59, _60,
27 _61, _62, _63, _64, N, ...) N
28#endif
29
30#ifndef PP_NARG
31 #define PP_NARG(...)
32 PP_ARG_N(__VA_ARGS__, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55,
33 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40,
34 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25,
35 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
36 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
37#endif
38
39#ifndef PP_EVAL_0
40 #define PP_EVAL_0(...) __VA_ARGS__
41#endif
42#ifndef PP_EVAL_1
43 #define PP_EVAL_1(...) PP_EVAL_0(PP_EVAL_0(PP_EVAL_0(__VA_ARGS__)))
44#endif
45#ifndef PP_EVAL_2
46 #define PP_EVAL_2(...) PP_EVAL_1(PP_EVAL_1(PP_EVAL_1(__VA_ARGS__)))
47#endif
48#ifndef PP_EVAL_3
49 #define PP_EVAL_3(...) PP_EVAL_2(PP_EVAL_2(PP_EVAL_2(__VA_ARGS__)))
50#endif
51#ifndef PP_EVAL_4
52 #define PP_EVAL_4(...) PP_EVAL_3(PP_EVAL_3(PP_EVAL_3(__VA_ARGS__)))
53#endif
54#ifndef PP_EVAL
55 #define PP_EVAL(...) PP_EVAL_4(PP_EVAL_4(PP_EVAL_4(__VA_ARGS__)))
56#endif
57
58#ifndef PP_FOREACH_END
59 #define PP_FOREACH_END(...)
60#endif
61#ifndef PP_FOREACH_OUT
62 #define PP_FOREACH_OUT
63#endif
64#ifndef PP_FOREACH_COMMA
65 #define PP_FOREACH_COMMA ,
66#endif
67
68#ifndef PP_FOREACH_GET_END2
69 #define PP_FOREACH_GET_END2() 0, PP_FOREACH_END
70#endif
71#ifndef PP_FOREACH_GET_END1
72 #define PP_FOREACH_GET_END1(...) PP_FOREACH_GET_END2
73#endif
74#ifndef PP_FOREACH_GET_END
75 #define PP_FOREACH_GET_END(...) PP_FOREACH_GET_END1
76#endif
77#ifndef PP_FOREACH_NEXT0
78 #define PP_FOREACH_NEXT0(test, next, ...) next PP_FOREACH_OUT
79#endif
80#ifndef PP_FOREACH_NEXT1
81 #define PP_FOREACH_NEXT1(test, next) PP_FOREACH_NEXT0(test, next, 0)
82#endif
83#ifndef PP_FOREACH_NEXT
84 #define PP_FOREACH_NEXT(test, next) PP_FOREACH_NEXT1(PP_FOREACH_GET_END test, next)
85#endif
86
87#ifndef PP_FOREACH_0
88 #define PP_FOREACH_0(f, x, peek, ...) f(x) PP_FOREACH_NEXT(peek, PP_FOREACH_1)(f, peek, __VA_ARGS__)
89#endif
90#ifndef PP_FOREACH_1
91 #define PP_FOREACH_1(f, x, peek, ...) f(x) PP_FOREACH_NEXT(peek, PP_FOREACH_0)(f, peek, __VA_ARGS__)
92#endif
93
94#ifndef PP_FOREACH_LIST_NEXT1
95 #define PP_FOREACH_LIST_NEXT1(test, next) PP_FOREACH_NEXT0(test, PP_FOREACH_COMMA next, 0)
96#endif
97#ifndef PP_FOREACH_LIST_NEXT
98 #define PP_FOREACH_LIST_NEXT(test, next) PP_FOREACH_LIST_NEXT1(PP_FOREACH_GET_END test, next)
99#endif
100
101#ifndef PP_FOREACH_LIST0
102 #define PP_FOREACH_LIST0(f, x, peek, ...) f(x) PP_FOREACH_LIST_NEXT(peek, PP_FOREACH_LIST1)(f, peek, __VA_ARGS__)
103#endif
104#ifndef PP_FOREACH_LIST1
105 #define PP_FOREACH_LIST1(f, x, peek, ...) f(x) PP_FOREACH_LIST_NEXT(peek, PP_FOREACH_LIST0)(f, peek, __VA_ARGS__)
106#endif
107
108/*
109 * Applies the function macro `f` to each of the remaining parameters.
110 * Taken from https://github.com/swansontec/map-macro/blob/master/map.h
111 */
112#ifndef PP_FOREACH
113 #define PP_FOREACH(f, ...) PP_EVAL(PP_FOREACH_1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
114#endif
#define PP_FOREACH_LIST1(f, x, peek,...)
Definition Preprocessor.h:105
#define PP_FOREACH_OUT
Definition Preprocessor.h:62
#define PP_FOREACH_GET_END2()
Definition Preprocessor.h:69
#define PP_FOREACH_NEXT1(test, next)
Definition Preprocessor.h:81
#define PP_FOREACH_GET_END(...)
Definition Preprocessor.h:75
#define PP_EVAL_0(...)
Definition Preprocessor.h:40
#define PP_FOREACH_NEXT(test, next)
Definition Preprocessor.h:84
#define PP_ARG_N( _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, N,...)
Definition Preprocessor.h:20
#define PP_EVAL(...)
Definition Preprocessor.h:55
#define PP_CONCAT(x, y)
Definition Preprocessor.h:4
#define PP_STR(...)
Definition Preprocessor.h:12
#define PP_FOREACH_COMMA
Definition Preprocessor.h:65
#define PP_FOREACH_LIST_NEXT(test, next)
Definition Preprocessor.h:98
#define PP_EVAL_4(...)
Definition Preprocessor.h:52
#define PP_FOREACH_1(f, x, peek,...)
Definition Preprocessor.h:91
#define PP_FOREACH_LIST0(f, x, peek,...)
Definition Preprocessor.h:102
#define PP_FOREACH_NEXT0(test, next,...)
Definition Preprocessor.h:78
#define PP_EVAL_3(...)
Definition Preprocessor.h:49
#define PP_FOREACH_END(...)
Definition Preprocessor.h:59
#define PP_EVAL_1(...)
Definition Preprocessor.h:43
#define PP_FOREACH_GET_END1(...)
Definition Preprocessor.h:72
#define PP_FOREACH_LIST_NEXT1(test, next)
Definition Preprocessor.h:95
#define PP_EVAL_2(...)
Definition Preprocessor.h:46
#define PP_FOREACH_0(f, x, peek,...)
Definition Preprocessor.h:88