1 |
|
---|
2 | // NO INCLUDE GUARDS, THE HEADER IS INTENDED FOR MULTIPLE INCLUSION
|
---|
3 |
|
---|
4 | #if !defined(BOOST_PP_IS_ITERATING)
|
---|
5 |
|
---|
6 | // Copyright Aleksey Gurtovoy 2000-2004
|
---|
7 | //
|
---|
8 | // Distributed under the Boost Software License, Version 1.0.
|
---|
9 | // (See accompanying file LICENSE_1_0.txt or copy at
|
---|
10 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
11 | //
|
---|
12 | // See http://www.boost.org/libs/mpl for documentation.
|
---|
13 |
|
---|
14 | // $Source: /cvsroot/boost/boost/boost/mpl/aux_/fold_impl_body.hpp,v $
|
---|
15 | // $Date: 2004/10/24 08:18:03 $
|
---|
16 | // $Revision: 1.8 $
|
---|
17 |
|
---|
18 | # include <boost/mpl/limits/unrolling.hpp>
|
---|
19 | # include <boost/mpl/aux_/preprocessor/repeat.hpp>
|
---|
20 | # include <boost/mpl/aux_/config/workaround.hpp>
|
---|
21 | # include <boost/mpl/aux_/config/ctps.hpp>
|
---|
22 | # include <boost/mpl/aux_/nttp_decl.hpp>
|
---|
23 | # include <boost/mpl/aux_/config/eti.hpp>
|
---|
24 |
|
---|
25 | # include <boost/preprocessor/iterate.hpp>
|
---|
26 | # include <boost/preprocessor/dec.hpp>
|
---|
27 | # include <boost/preprocessor/cat.hpp>
|
---|
28 |
|
---|
29 | // local macros, #undef-ined at the end of the header
|
---|
30 |
|
---|
31 | # define AUX778076_ITER_FOLD_STEP(unused, i, unused2) \
|
---|
32 | typedef typename apply2< \
|
---|
33 | ForwardOp \
|
---|
34 | , BOOST_PP_CAT(state,i) \
|
---|
35 | , AUX778076_FOLD_IMPL_OP(BOOST_PP_CAT(iter,i)) \
|
---|
36 | >::type BOOST_PP_CAT(state,BOOST_PP_INC(i)); \
|
---|
37 | typedef typename mpl::next<BOOST_PP_CAT(iter,i)>::type \
|
---|
38 | BOOST_PP_CAT(iter,BOOST_PP_INC(i)); \
|
---|
39 | /**/
|
---|
40 |
|
---|
41 | # define AUX778076_FOLD_IMPL_NAME \
|
---|
42 | BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_impl) \
|
---|
43 | /**/
|
---|
44 |
|
---|
45 | # define AUX778076_FOLD_CHUNK_NAME \
|
---|
46 | BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_chunk) \
|
---|
47 | /**/
|
---|
48 |
|
---|
49 | namespace boost { namespace mpl { namespace aux {
|
---|
50 |
|
---|
51 | /// forward declaration
|
---|
52 | template<
|
---|
53 | BOOST_MPL_AUX_NTTP_DECL(int, N)
|
---|
54 | , typename First
|
---|
55 | , typename Last
|
---|
56 | , typename State
|
---|
57 | , typename ForwardOp
|
---|
58 | >
|
---|
59 | struct AUX778076_FOLD_IMPL_NAME;
|
---|
60 |
|
---|
61 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
---|
62 |
|
---|
63 | # if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
|
---|
64 |
|
---|
65 | # define BOOST_PP_ITERATION_PARAMS_1 \
|
---|
66 | (3,(0, BOOST_MPL_LIMIT_UNROLLING, <boost/mpl/aux_/fold_impl_body.hpp>))
|
---|
67 | # include BOOST_PP_ITERATE()
|
---|
68 |
|
---|
69 | // implementation for N that exceeds BOOST_MPL_LIMIT_UNROLLING
|
---|
70 | template<
|
---|
71 | BOOST_MPL_AUX_NTTP_DECL(int, N)
|
---|
72 | , typename First
|
---|
73 | , typename Last
|
---|
74 | , typename State
|
---|
75 | , typename ForwardOp
|
---|
76 | >
|
---|
77 | struct AUX778076_FOLD_IMPL_NAME
|
---|
78 | {
|
---|
79 | typedef AUX778076_FOLD_IMPL_NAME<
|
---|
80 | BOOST_MPL_LIMIT_UNROLLING
|
---|
81 | , First
|
---|
82 | , Last
|
---|
83 | , State
|
---|
84 | , ForwardOp
|
---|
85 | > chunk_;
|
---|
86 |
|
---|
87 | typedef AUX778076_FOLD_IMPL_NAME<
|
---|
88 | ( (N - BOOST_MPL_LIMIT_UNROLLING) < 0 ? 0 : N - BOOST_MPL_LIMIT_UNROLLING )
|
---|
89 | , typename chunk_::iterator
|
---|
90 | , Last
|
---|
91 | , typename chunk_::state
|
---|
92 | , ForwardOp
|
---|
93 | > res_;
|
---|
94 |
|
---|
95 | typedef typename res_::state state;
|
---|
96 | typedef typename res_::iterator iterator;
|
---|
97 | };
|
---|
98 |
|
---|
99 | // fallback implementation for sequences of unknown size
|
---|
100 | template<
|
---|
101 | typename First
|
---|
102 | , typename Last
|
---|
103 | , typename State
|
---|
104 | , typename ForwardOp
|
---|
105 | >
|
---|
106 | struct AUX778076_FOLD_IMPL_NAME<-1,First,Last,State,ForwardOp>
|
---|
107 | : AUX778076_FOLD_IMPL_NAME<
|
---|
108 | -1
|
---|
109 | , typename mpl::next<First>::type
|
---|
110 | , Last
|
---|
111 | , typename apply2<ForwardOp,State,AUX778076_FOLD_IMPL_OP(First)>::type
|
---|
112 | , ForwardOp
|
---|
113 | >
|
---|
114 | {
|
---|
115 | };
|
---|
116 |
|
---|
117 | template<
|
---|
118 | typename Last
|
---|
119 | , typename State
|
---|
120 | , typename ForwardOp
|
---|
121 | >
|
---|
122 | struct AUX778076_FOLD_IMPL_NAME<-1,Last,Last,State,ForwardOp>
|
---|
123 | {
|
---|
124 | typedef State state;
|
---|
125 | typedef Last iterator;
|
---|
126 | };
|
---|
127 |
|
---|
128 | # else // BOOST_WORKAROUND(__BORLANDC__, < 0x600)
|
---|
129 |
|
---|
130 | // Borland have some serious problems with the unrolled version, so
|
---|
131 | // we always use a basic implementation
|
---|
132 | template<
|
---|
133 | BOOST_MPL_AUX_NTTP_DECL(int, N)
|
---|
134 | , typename First
|
---|
135 | , typename Last
|
---|
136 | , typename State
|
---|
137 | , typename ForwardOp
|
---|
138 | >
|
---|
139 | struct AUX778076_FOLD_IMPL_NAME
|
---|
140 | {
|
---|
141 | typedef AUX778076_FOLD_IMPL_NAME<
|
---|
142 | -1
|
---|
143 | , typename mpl::next<First>::type
|
---|
144 | , Last
|
---|
145 | , typename apply2<ForwardOp,State,AUX778076_FOLD_IMPL_OP(First)>::type
|
---|
146 | , ForwardOp
|
---|
147 | > res_;
|
---|
148 |
|
---|
149 | typedef typename res_::state state;
|
---|
150 | typedef typename res_::iterator iterator;
|
---|
151 | typedef state type;
|
---|
152 | };
|
---|
153 |
|
---|
154 | template<
|
---|
155 | BOOST_MPL_AUX_NTTP_DECL(int, N)
|
---|
156 | , typename Last
|
---|
157 | , typename State
|
---|
158 | , typename ForwardOp
|
---|
159 | >
|
---|
160 | struct AUX778076_FOLD_IMPL_NAME<N,Last,Last,State,ForwardOp >
|
---|
161 | {
|
---|
162 | typedef State state;
|
---|
163 | typedef Last iterator;
|
---|
164 | typedef state type;
|
---|
165 | };
|
---|
166 |
|
---|
167 | # endif // BOOST_WORKAROUND(__BORLANDC__, < 0x600)
|
---|
168 |
|
---|
169 | #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
170 |
|
---|
171 | template< BOOST_MPL_AUX_NTTP_DECL(int, N) >
|
---|
172 | struct AUX778076_FOLD_CHUNK_NAME;
|
---|
173 |
|
---|
174 | # define BOOST_PP_ITERATION_PARAMS_1 \
|
---|
175 | (3,(0, BOOST_MPL_LIMIT_UNROLLING, <boost/mpl/aux_/fold_impl_body.hpp>))
|
---|
176 | # include BOOST_PP_ITERATE()
|
---|
177 |
|
---|
178 | // implementation for N that exceeds BOOST_MPL_LIMIT_UNROLLING
|
---|
179 | template< BOOST_MPL_AUX_NTTP_DECL(int, N) >
|
---|
180 | struct AUX778076_FOLD_CHUNK_NAME
|
---|
181 | {
|
---|
182 | template<
|
---|
183 | typename First
|
---|
184 | , typename Last
|
---|
185 | , typename State
|
---|
186 | , typename ForwardOp
|
---|
187 | >
|
---|
188 | struct result_
|
---|
189 | {
|
---|
190 | typedef AUX778076_FOLD_IMPL_NAME<
|
---|
191 | BOOST_MPL_LIMIT_UNROLLING
|
---|
192 | , First
|
---|
193 | , Last
|
---|
194 | , State
|
---|
195 | , ForwardOp
|
---|
196 | > chunk_;
|
---|
197 |
|
---|
198 | typedef AUX778076_FOLD_IMPL_NAME<
|
---|
199 | ( (N - BOOST_MPL_LIMIT_UNROLLING) < 0 ? 0 : N - BOOST_MPL_LIMIT_UNROLLING )
|
---|
200 | , typename chunk_::iterator
|
---|
201 | , Last
|
---|
202 | , typename chunk_::state
|
---|
203 | , ForwardOp
|
---|
204 | > res_;
|
---|
205 |
|
---|
206 | typedef typename res_::state state;
|
---|
207 | typedef typename res_::iterator iterator;
|
---|
208 | };
|
---|
209 | };
|
---|
210 |
|
---|
211 | // fallback implementation for sequences of unknown size
|
---|
212 | template<
|
---|
213 | typename First
|
---|
214 | , typename Last
|
---|
215 | , typename State
|
---|
216 | , typename ForwardOp
|
---|
217 | >
|
---|
218 | struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step);
|
---|
219 |
|
---|
220 | template<
|
---|
221 | typename Last
|
---|
222 | , typename State
|
---|
223 | >
|
---|
224 | struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_null_step)
|
---|
225 | {
|
---|
226 | typedef Last iterator;
|
---|
227 | typedef State state;
|
---|
228 | };
|
---|
229 |
|
---|
230 | template<>
|
---|
231 | struct AUX778076_FOLD_CHUNK_NAME<-1>
|
---|
232 | {
|
---|
233 | template<
|
---|
234 | typename First
|
---|
235 | , typename Last
|
---|
236 | , typename State
|
---|
237 | , typename ForwardOp
|
---|
238 | >
|
---|
239 | struct result_
|
---|
240 | {
|
---|
241 | typedef typename if_<
|
---|
242 | typename is_same<First,Last>::type
|
---|
243 | , BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_null_step)<Last,State>
|
---|
244 | , BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step)<First,Last,State,ForwardOp>
|
---|
245 | >::type res_;
|
---|
246 |
|
---|
247 | typedef typename res_::state state;
|
---|
248 | typedef typename res_::iterator iterator;
|
---|
249 | };
|
---|
250 |
|
---|
251 | #if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
|
---|
252 | /// ETI workaround
|
---|
253 | template<> struct result_<int,int,int,int>
|
---|
254 | {
|
---|
255 | typedef int state;
|
---|
256 | typedef int iterator;
|
---|
257 | };
|
---|
258 | #endif
|
---|
259 | };
|
---|
260 |
|
---|
261 | template<
|
---|
262 | typename First
|
---|
263 | , typename Last
|
---|
264 | , typename State
|
---|
265 | , typename ForwardOp
|
---|
266 | >
|
---|
267 | struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step)
|
---|
268 | {
|
---|
269 | // can't inherit here - it breaks MSVC 7.0
|
---|
270 | typedef AUX778076_FOLD_CHUNK_NAME<-1>::template result_<
|
---|
271 | typename mpl::next<First>::type
|
---|
272 | , Last
|
---|
273 | , typename apply2<ForwardOp,State,AUX778076_FOLD_IMPL_OP(First)>::type
|
---|
274 | , ForwardOp
|
---|
275 | > chunk_;
|
---|
276 |
|
---|
277 | typedef typename chunk_::state state;
|
---|
278 | typedef typename chunk_::iterator iterator;
|
---|
279 | };
|
---|
280 |
|
---|
281 | template<
|
---|
282 | BOOST_MPL_AUX_NTTP_DECL(int, N)
|
---|
283 | , typename First
|
---|
284 | , typename Last
|
---|
285 | , typename State
|
---|
286 | , typename ForwardOp
|
---|
287 | >
|
---|
288 | struct AUX778076_FOLD_IMPL_NAME
|
---|
289 | : AUX778076_FOLD_CHUNK_NAME<N>
|
---|
290 | ::template result_<First,Last,State,ForwardOp>
|
---|
291 | {
|
---|
292 | };
|
---|
293 |
|
---|
294 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
295 |
|
---|
296 | }}}
|
---|
297 |
|
---|
298 | # undef AUX778076_FOLD_IMPL_NAME
|
---|
299 | # undef AUX778076_FOLD_CHUNK_NAME
|
---|
300 | # undef AUX778076_ITER_FOLD_STEP
|
---|
301 |
|
---|
302 | #undef AUX778076_FOLD_IMPL_OP
|
---|
303 | #undef AUX778076_FOLD_IMPL_NAME_PREFIX
|
---|
304 |
|
---|
305 | ///// iteration
|
---|
306 |
|
---|
307 | #else
|
---|
308 |
|
---|
309 | # define n_ BOOST_PP_FRAME_ITERATION(1)
|
---|
310 |
|
---|
311 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
---|
312 |
|
---|
313 | template<
|
---|
314 | typename First
|
---|
315 | , typename Last
|
---|
316 | , typename State
|
---|
317 | , typename ForwardOp
|
---|
318 | >
|
---|
319 | struct AUX778076_FOLD_IMPL_NAME<n_,First,Last,State,ForwardOp>
|
---|
320 | {
|
---|
321 | typedef First iter0;
|
---|
322 | typedef State state0;
|
---|
323 |
|
---|
324 | BOOST_MPL_PP_REPEAT(n_, AUX778076_ITER_FOLD_STEP, unused)
|
---|
325 |
|
---|
326 | typedef BOOST_PP_CAT(state,n_) state;
|
---|
327 | typedef BOOST_PP_CAT(iter,n_) iterator;
|
---|
328 | };
|
---|
329 |
|
---|
330 | #else
|
---|
331 |
|
---|
332 | template<> struct AUX778076_FOLD_CHUNK_NAME<n_>
|
---|
333 | {
|
---|
334 | template<
|
---|
335 | typename First
|
---|
336 | , typename Last
|
---|
337 | , typename State
|
---|
338 | , typename ForwardOp
|
---|
339 | >
|
---|
340 | struct result_
|
---|
341 | {
|
---|
342 | typedef First iter0;
|
---|
343 | typedef State state0;
|
---|
344 |
|
---|
345 | BOOST_MPL_PP_REPEAT(n_, AUX778076_ITER_FOLD_STEP, unused)
|
---|
346 |
|
---|
347 | typedef BOOST_PP_CAT(state,n_) state;
|
---|
348 | typedef BOOST_PP_CAT(iter,n_) iterator;
|
---|
349 | };
|
---|
350 |
|
---|
351 | #if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
|
---|
352 | /// ETI workaround
|
---|
353 | template<> struct result_<int,int,int,int>
|
---|
354 | {
|
---|
355 | typedef int state;
|
---|
356 | typedef int iterator;
|
---|
357 | };
|
---|
358 | #endif
|
---|
359 | };
|
---|
360 |
|
---|
361 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
362 |
|
---|
363 | # undef n_
|
---|
364 |
|
---|
365 | #endif // BOOST_PP_IS_ITERATING
|
---|