1 | # /* ************************************************************************** |
2 | # * * |
3 | # * (C) Copyright Paul Mensonides 2002. |
4 | # * Distributed under the Boost Software License, Version 1.0. (See |
5 | # * accompanying file LICENSE_1_0.txt or copy at |
6 | # * http://www.boost.org/LICENSE_1_0.txt) |
7 | # * * |
8 | # ************************************************************************** */ |
9 | # |
10 | # /* See http://www.boost.org for most recent version. */ |
11 | # |
12 | # include <boost/preprocessor/config/limits.hpp> |
13 | # include <boost/preprocessor/arithmetic/inc.hpp> |
14 | # include <boost/preprocessor/cat.hpp> |
15 | # include <boost/preprocessor/comparison/equal.hpp> |
16 | # include <boost/preprocessor/comparison/not_equal.hpp> |
17 | # include <boost/preprocessor/control/iif.hpp> |
18 | # include <boost/preprocessor/facilities/intercept.hpp> |
19 | # include <boost/preprocessor/logical/bitor.hpp> |
20 | # include <boost/preprocessor/repetition.hpp> |
21 | # include "test.h" |
22 | |
23 | # define MAX 10 |
24 | |
25 | # define NTH(z, n, data) data ## n |
26 | |
27 | int add(BOOST_PP_ENUM_PARAMS(MAX, int x)) { |
28 | return BOOST_PP_REPEAT(MAX, NTH, + x); |
29 | } |
30 | |
31 | const int r = add(BOOST_PP_ENUM_PARAMS(MAX, 1 BOOST_PP_INTERCEPT)); |
32 | |
33 | # define CONSTANT(z, n, text) BOOST_PP_CAT(text, n) = n |
34 | const int BOOST_PP_ENUM(MAX, CONSTANT, default_param_); |
35 | |
36 | # define TEST(n) \ |
37 | void BOOST_PP_CAT(test_enum_params, n)(BOOST_PP_ENUM_PARAMS(n, int x)); \ |
38 | void BOOST_PP_CAT(test_enum_params_with_a_default, n)(BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(n, int x, 0)); \ |
39 | void BOOST_PP_CAT(test_enum_params_with_defaults, n)(BOOST_PP_ENUM_PARAMS_WITH_DEFAULTS(n, int x, default_param_)); |
40 | |
41 | TEST(0) |
42 | TEST(MAX) |
43 | |
44 | template<BOOST_PP_ENUM_PARAMS(MAX, class T)> struct no_rescan; |
45 | |
46 | # define F1(z, n, p) p n |
47 | BEGIN 1 + (4+5+6) BOOST_PP_REPEAT_FROM_TO(4, 7, F1, -) END |
48 | |
49 | # if BOOST_PP_LIMIT_REPEAT == 512 |
50 | |
51 | # define RP512M(z,n,data) \ |
52 | struct BOOST_PP_CAT(data,BOOST_PP_INC(n)); \ |
53 | /* */ |
54 | |
55 | BOOST_PP_REPEAT_FROM_TO(508,512,RP512M,r512_t) |
56 | |
57 | #endif |
58 | |
59 | # if BOOST_PP_LIMIT_REPEAT == 1024 |
60 | |
61 | # define RP1024M(z,n,data) \ |
62 | struct BOOST_PP_CAT(data,BOOST_PP_INC(n)); \ |
63 | /* */ |
64 | |
65 | BOOST_PP_REPEAT_FROM_TO(1010,1024,RP1024M,r1024_t) |
66 | |
67 | #endif |
68 | |
69 | # define PRED(r, state) BOOST_PP_NOT_EQUAL(state, BOOST_PP_INC(MAX)) |
70 | # define OP(r, state) BOOST_PP_INC(state) |
71 | # define MACRO(r, state) BOOST_PP_COMMA_IF(BOOST_PP_NOT_EQUAL(state, 1)) BOOST_PP_CAT(class T, state) |
72 | |
73 | template<BOOST_PP_FOR(1, PRED, OP, MACRO)> struct for_test; |
74 | |
75 | # if BOOST_PP_LIMIT_FOR == 512 |
76 | |
77 | # define PRED512(r, state) BOOST_PP_NOT_EQUAL(state, 512) |
78 | |
79 | # define MACRO512_NUL(state) |
80 | |
81 | # define MACRO512_OUT(state) struct BOOST_PP_CAT(f_512t,state); |
82 | |
83 | # define MACRO512(r, state) \ |
84 | BOOST_PP_IIF \ |
85 | ( \ |
86 | BOOST_PP_BITOR \ |
87 | ( \ |
88 | BOOST_PP_BITOR \ |
89 | ( \ |
90 | BOOST_PP_EQUAL(state,100), \ |
91 | BOOST_PP_EQUAL(state,200) \ |
92 | ), \ |
93 | BOOST_PP_BITOR \ |
94 | ( \ |
95 | BOOST_PP_BITOR \ |
96 | ( \ |
97 | BOOST_PP_EQUAL(state,300), \ |
98 | BOOST_PP_EQUAL(state,400) \ |
99 | ), \ |
100 | BOOST_PP_EQUAL(state,500) \ |
101 | ) \ |
102 | ), \ |
103 | MACRO512_OUT, \ |
104 | MACRO512_NUL \ |
105 | ) \ |
106 | (state) \ |
107 | /* */ |
108 | |
109 | BOOST_PP_FOR(0, PRED512, OP, MACRO512) |
110 | |
111 | #endif |
112 | |
113 | # if BOOST_PP_LIMIT_FOR == 1024 |
114 | |
115 | # define PRED1024(r, state) BOOST_PP_NOT_EQUAL(state, 1024) |
116 | |
117 | # define MACRO1024_NUL(state) |
118 | |
119 | # define MACRO1024_OUT(state) struct BOOST_PP_CAT(f_1024t,state); |
120 | |
121 | # define MACRO1024(r, state) \ |
122 | BOOST_PP_IIF \ |
123 | ( \ |
124 | BOOST_PP_BITOR \ |
125 | ( \ |
126 | BOOST_PP_BITOR \ |
127 | ( \ |
128 | BOOST_PP_BITOR \ |
129 | ( \ |
130 | BOOST_PP_EQUAL(state,100), \ |
131 | BOOST_PP_EQUAL(state,200) \ |
132 | ), \ |
133 | BOOST_PP_BITOR \ |
134 | ( \ |
135 | BOOST_PP_BITOR \ |
136 | ( \ |
137 | BOOST_PP_EQUAL(state,300), \ |
138 | BOOST_PP_EQUAL(state,400) \ |
139 | ), \ |
140 | BOOST_PP_EQUAL(state,500) \ |
141 | ) \ |
142 | ), \ |
143 | BOOST_PP_BITOR \ |
144 | ( \ |
145 | BOOST_PP_BITOR \ |
146 | ( \ |
147 | BOOST_PP_EQUAL(state,600), \ |
148 | BOOST_PP_EQUAL(state,700) \ |
149 | ), \ |
150 | BOOST_PP_BITOR \ |
151 | ( \ |
152 | BOOST_PP_BITOR \ |
153 | ( \ |
154 | BOOST_PP_EQUAL(state,800), \ |
155 | BOOST_PP_EQUAL(state,900) \ |
156 | ), \ |
157 | BOOST_PP_EQUAL(state,1000) \ |
158 | ) \ |
159 | ) \ |
160 | ), \ |
161 | MACRO1024_OUT, \ |
162 | MACRO1024_NUL \ |
163 | ) \ |
164 | (state) \ |
165 | /* */ |
166 | |
167 | BOOST_PP_FOR(0, PRED1024, OP, MACRO1024) |
168 | |
169 | #endif |
170 | |