blob: 838e63e7f2b3cc3e7465e6093f1e4a9d3076cf08 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001
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// $Id: reverse_fold_impl_body.hpp 49267 2008-10-11 06:19:02Z agurtovoy $
15// $Date: 2008-10-10 23:19:02 -0700 (Fri, 10 Oct 2008) $
16// $Revision: 49267 $
17
18# include <ndnboost/mpl/limits/unrolling.hpp>
19# include <ndnboost/mpl/aux_/preprocessor/repeat.hpp>
20# include <ndnboost/mpl/aux_/config/ctps.hpp>
21# include <ndnboost/mpl/aux_/nttp_decl.hpp>
22
23# include <ndnboost/preprocessor/arithmetic/sub.hpp>
24# include <ndnboost/preprocessor/iterate.hpp>
25# include <ndnboost/preprocessor/dec.hpp>
26# include <ndnboost/preprocessor/inc.hpp>
27# include <ndnboost/preprocessor/cat.hpp>
28
29// local macros, #undef-ined at the end of the header
30
31# define AUX778076_ITER_FOLD_FORWARD_STEP(unused, n_, unused2) \
32 typedef typename apply2< \
33 ForwardOp \
34 , BOOST_PP_CAT(fwd_state,n_) \
35 , AUX778076_FOLD_IMPL_OP(BOOST_PP_CAT(iter,n_)) \
36 >::type BOOST_PP_CAT(fwd_state,BOOST_PP_INC(n_)); \
37 typedef typename mpl::next<BOOST_PP_CAT(iter,n_)>::type \
38 BOOST_PP_CAT(iter,BOOST_PP_INC(n_)); \
39 /**/
40
41# define AUX778076_ITER_FOLD_BACKWARD_STEP_FUNC(n_) \
42 typedef typename apply2< \
43 BackwardOp \
44 , BOOST_PP_CAT(bkwd_state,n_) \
45 , AUX778076_FOLD_IMPL_OP(BOOST_PP_CAT(iter,BOOST_PP_DEC(n_))) \
46 >::type BOOST_PP_CAT(bkwd_state,BOOST_PP_DEC(n_)); \
47 /**/
48
49# define AUX778076_ITER_FOLD_BACKWARD_STEP(unused, n_, j) \
50 AUX778076_ITER_FOLD_BACKWARD_STEP_FUNC( \
51 BOOST_PP_SUB_D(1,j,n_) \
52 ) \
53 /**/
54
55# define AUX778076_FIRST_BACKWARD_STATE_TYPEDEF(n_) \
56 typedef typename nested_chunk::state BOOST_PP_CAT(bkwd_state,n_);
57 /**/
58
59# define AUX778076_FOLD_IMPL_NAME \
60 BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_impl) \
61 /**/
62
63# define AUX778076_FOLD_CHUNK_NAME \
64 BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_chunk) \
65 /**/
66
67namespace ndnboost { namespace mpl { namespace aux {
68
69/// forward declaration
70template<
71 BOOST_MPL_AUX_NTTP_DECL(long, N)
72 , typename First
73 , typename Last
74 , typename State
75 , typename BackwardOp
76 , typename ForwardOp
77 >
78struct AUX778076_FOLD_IMPL_NAME;
79
80#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
81 && !defined(BOOST_MPL_CFG_NO_NONTYPE_TEMPLATE_PARTIAL_SPEC)
82
83# define BOOST_PP_ITERATION_PARAMS_1 \
84 (3,(0, BOOST_MPL_LIMIT_UNROLLING, <ndnboost/mpl/aux_/reverse_fold_impl_body.hpp>))
85# include BOOST_PP_ITERATE()
86
87// implementation for N that exceeds BOOST_MPL_LIMIT_UNROLLING
88template<
89 BOOST_MPL_AUX_NTTP_DECL(long, N)
90 , typename First
91 , typename Last
92 , typename State
93 , typename BackwardOp
94 , typename ForwardOp
95 >
96struct AUX778076_FOLD_IMPL_NAME
97{
98 typedef First iter0;
99 typedef State fwd_state0;
100
101 BOOST_MPL_PP_REPEAT(
102 BOOST_MPL_LIMIT_UNROLLING
103 , AUX778076_ITER_FOLD_FORWARD_STEP
104 , unused
105 )
106
107 typedef AUX778076_FOLD_IMPL_NAME<
108 ( (N - BOOST_MPL_LIMIT_UNROLLING) < 0 ? 0 : N - BOOST_MPL_LIMIT_UNROLLING )
109 , BOOST_PP_CAT(iter,BOOST_MPL_LIMIT_UNROLLING)
110 , Last
111 , BOOST_PP_CAT(fwd_state,BOOST_MPL_LIMIT_UNROLLING)
112 , BackwardOp
113 , ForwardOp
114 > nested_chunk;
115
116 AUX778076_FIRST_BACKWARD_STATE_TYPEDEF(BOOST_MPL_LIMIT_UNROLLING)
117
118 BOOST_MPL_PP_REPEAT(
119 BOOST_MPL_LIMIT_UNROLLING
120 , AUX778076_ITER_FOLD_BACKWARD_STEP
121 , BOOST_MPL_LIMIT_UNROLLING
122 )
123
124 typedef bkwd_state0 state;
125 typedef typename nested_chunk::iterator iterator;
126};
127
128// fallback implementation for sequences of unknown size
129template<
130 typename First
131 , typename Last
132 , typename State
133 , typename BackwardOp
134 , typename ForwardOp
135 >
136struct AUX778076_FOLD_IMPL_NAME<-1,First,Last,State,BackwardOp,ForwardOp>
137{
138 typedef AUX778076_FOLD_IMPL_NAME<
139 -1
140 , typename mpl::next<First>::type
141 , Last
142 , typename apply2<ForwardOp,State,AUX778076_FOLD_IMPL_OP(First)>::type
143 , BackwardOp
144 , ForwardOp
145 > nested_step;
146
147 typedef typename apply2<
148 BackwardOp
149 , typename nested_step::state
150 , AUX778076_FOLD_IMPL_OP(First)
151 >::type state;
152
153 typedef typename nested_step::iterator iterator;
154};
155
156template<
157 typename Last
158 , typename State
159 , typename BackwardOp
160 , typename ForwardOp
161 >
162struct AUX778076_FOLD_IMPL_NAME<-1,Last,Last,State,BackwardOp,ForwardOp>
163{
164 typedef State state;
165 typedef Last iterator;
166};
167
168#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
169
170template< BOOST_MPL_AUX_NTTP_DECL(long, N) >
171struct AUX778076_FOLD_CHUNK_NAME;
172
173# define BOOST_PP_ITERATION_PARAMS_1 \
174 (3,(0, BOOST_MPL_LIMIT_UNROLLING, <ndnboost/mpl/aux_/reverse_fold_impl_body.hpp>))
175# include BOOST_PP_ITERATE()
176
177// implementation for N that exceeds BOOST_MPL_LIMIT_UNROLLING
178template< BOOST_MPL_AUX_NTTP_DECL(long, N) >
179struct AUX778076_FOLD_CHUNK_NAME
180{
181 template<
182 typename First
183 , typename Last
184 , typename State
185 , typename BackwardOp
186 , typename ForwardOp
187 >
188 struct result_
189 {
190 typedef First iter0;
191 typedef State fwd_state0;
192
193 BOOST_MPL_PP_REPEAT(
194 BOOST_MPL_LIMIT_UNROLLING
195 , AUX778076_ITER_FOLD_FORWARD_STEP
196 , unused
197 )
198
199 typedef AUX778076_FOLD_IMPL_NAME<
200 ( (N - BOOST_MPL_LIMIT_UNROLLING) < 0 ? 0 : N - BOOST_MPL_LIMIT_UNROLLING )
201 , BOOST_PP_CAT(iter,BOOST_MPL_LIMIT_UNROLLING)
202 , Last
203 , BOOST_PP_CAT(fwd_state,BOOST_MPL_LIMIT_UNROLLING)
204 , BackwardOp
205 , ForwardOp
206 > nested_chunk;
207
208 AUX778076_FIRST_BACKWARD_STATE_TYPEDEF(BOOST_MPL_LIMIT_UNROLLING)
209
210 BOOST_MPL_PP_REPEAT(
211 BOOST_MPL_LIMIT_UNROLLING
212 , AUX778076_ITER_FOLD_BACKWARD_STEP
213 , BOOST_MPL_LIMIT_UNROLLING
214 )
215
216 typedef bkwd_state0 state;
217 typedef typename nested_chunk::iterator iterator;
218 };
219};
220
221// fallback implementation for sequences of unknown size
222template<
223 typename First
224 , typename Last
225 , typename State
226 , typename BackwardOp
227 , typename ForwardOp
228 >
229struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step);
230
231template<
232 typename Last
233 , typename State
234 >
235struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_null_step)
236{
237 typedef Last iterator;
238 typedef State state;
239};
240
241template<>
242struct AUX778076_FOLD_CHUNK_NAME<-1>
243{
244 template<
245 typename First
246 , typename Last
247 , typename State
248 , typename BackwardOp
249 , typename ForwardOp
250 >
251 struct result_
252 {
253 typedef typename if_<
254 typename is_same<First,Last>::type
255 , BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_null_step)<Last,State>
256 , BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step)<First,Last,State,BackwardOp,ForwardOp>
257 >::type res_;
258
259 typedef typename res_::state state;
260 typedef typename res_::iterator iterator;
261 };
262
263#if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
264 /// ETI workaround
265 template<> struct result_<int,int,int,int,int>
266 {
267 typedef int state;
268 typedef int iterator;
269 };
270#endif
271};
272
273template<
274 typename First
275 , typename Last
276 , typename State
277 , typename BackwardOp
278 , typename ForwardOp
279 >
280struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step)
281{
282 typedef AUX778076_FOLD_CHUNK_NAME<-1>::template result_<
283 typename mpl::next<First>::type
284 , Last
285 , typename apply2<ForwardOp,State,AUX778076_FOLD_IMPL_OP(First)>::type
286 , BackwardOp
287 , ForwardOp
288 > nested_step;
289
290 typedef typename apply2<
291 BackwardOp
292 , typename nested_step::state
293 , AUX778076_FOLD_IMPL_OP(First)
294 >::type state;
295
296 typedef typename nested_step::iterator iterator;
297};
298
299template<
300 BOOST_MPL_AUX_NTTP_DECL(long, N)
301 , typename First
302 , typename Last
303 , typename State
304 , typename BackwardOp
305 , typename ForwardOp
306 >
307struct AUX778076_FOLD_IMPL_NAME
308 : AUX778076_FOLD_CHUNK_NAME<N>
309 ::template result_<First,Last,State,BackwardOp,ForwardOp>
310{
311};
312
313#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
314
315}}}
316
317# undef AUX778076_FIRST_BACKWARD_STATE_TYPEDEF
318# undef AUX778076_ITER_FOLD_BACKWARD_STEP
319# undef AUX778076_ITER_FOLD_BACKWARD_STEP_FUNC
320# undef AUX778076_ITER_FOLD_FORWARD_STEP
321
322#undef AUX778076_FOLD_IMPL_OP
323#undef AUX778076_FOLD_IMPL_NAME_PREFIX
324
325///// iteration
326
327#else
328
329# define n_ BOOST_PP_FRAME_ITERATION(1)
330
331#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
332 && !defined(BOOST_MPL_CFG_NO_NONTYPE_TEMPLATE_PARTIAL_SPEC)
333
334template<
335 typename First
336 , typename Last
337 , typename State
338 , typename BackwardOp
339 , typename ForwardOp
340 >
341struct AUX778076_FOLD_IMPL_NAME<n_,First,Last,State,BackwardOp,ForwardOp>
342{
343 typedef First iter0;
344 typedef State fwd_state0;
345
346 BOOST_MPL_PP_REPEAT(
347 n_
348 , AUX778076_ITER_FOLD_FORWARD_STEP
349 , unused
350 )
351
352 typedef BOOST_PP_CAT(fwd_state,n_) BOOST_PP_CAT(bkwd_state,n_);
353
354 BOOST_MPL_PP_REPEAT(
355 n_
356 , AUX778076_ITER_FOLD_BACKWARD_STEP
357 , n_
358 )
359
360 typedef bkwd_state0 state;
361 typedef BOOST_PP_CAT(iter,n_) iterator;
362};
363
364#else
365
366template<> struct AUX778076_FOLD_CHUNK_NAME<n_>
367{
368 template<
369 typename First
370 , typename Last
371 , typename State
372 , typename BackwardOp
373 , typename ForwardOp
374 >
375 struct result_
376 {
377 typedef First iter0;
378 typedef State fwd_state0;
379
380 BOOST_MPL_PP_REPEAT(
381 n_
382 , AUX778076_ITER_FOLD_FORWARD_STEP
383 , unused
384 )
385
386 typedef BOOST_PP_CAT(fwd_state,n_) BOOST_PP_CAT(bkwd_state,n_);
387
388 BOOST_MPL_PP_REPEAT(
389 n_
390 , AUX778076_ITER_FOLD_BACKWARD_STEP
391 , n_
392 )
393
394 typedef bkwd_state0 state;
395 typedef BOOST_PP_CAT(iter,n_) iterator;
396 };
397
398#if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
399 /// ETI workaround
400 template<> struct result_<int,int,int,int,int>
401 {
402 typedef int state;
403 typedef int iterator;
404 };
405#endif
406};
407
408#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
409
410# undef n_
411
412#endif // BOOST_PP_IS_ITERATING