blob: 3ca6eee56a05c0197b42b72a0acba41f329cd068 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001
2// NO INCLUDE GUARDS, THE HEADER IS INTENDED FOR MULTIPLE INCLUSION!
3
Jeff Thompson3d613fd2013-10-15 15:39:04 -07004#if !defined(NDNBOOST_PP_IS_ITERATING)
Jeff Thompsona28eed82013-08-22 16:21:10 -07005
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 \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070034 , NDNBOOST_PP_CAT(fwd_state,n_) \
35 , AUX778076_FOLD_IMPL_OP(NDNBOOST_PP_CAT(iter,n_)) \
36 >::type NDNBOOST_PP_CAT(fwd_state,NDNBOOST_PP_INC(n_)); \
37 typedef typename mpl::next<NDNBOOST_PP_CAT(iter,n_)>::type \
38 NDNBOOST_PP_CAT(iter,NDNBOOST_PP_INC(n_)); \
Jeff Thompsona28eed82013-08-22 16:21:10 -070039 /**/
40
41# define AUX778076_ITER_FOLD_BACKWARD_STEP_FUNC(n_) \
42 typedef typename apply2< \
43 BackwardOp \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070044 , NDNBOOST_PP_CAT(bkwd_state,n_) \
45 , AUX778076_FOLD_IMPL_OP(NDNBOOST_PP_CAT(iter,NDNBOOST_PP_DEC(n_))) \
46 >::type NDNBOOST_PP_CAT(bkwd_state,NDNBOOST_PP_DEC(n_)); \
Jeff Thompsona28eed82013-08-22 16:21:10 -070047 /**/
48
49# define AUX778076_ITER_FOLD_BACKWARD_STEP(unused, n_, j) \
50 AUX778076_ITER_FOLD_BACKWARD_STEP_FUNC( \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070051 NDNBOOST_PP_SUB_D(1,j,n_) \
Jeff Thompsona28eed82013-08-22 16:21:10 -070052 ) \
53 /**/
54
55# define AUX778076_FIRST_BACKWARD_STATE_TYPEDEF(n_) \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070056 typedef typename nested_chunk::state NDNBOOST_PP_CAT(bkwd_state,n_);
Jeff Thompsona28eed82013-08-22 16:21:10 -070057 /**/
58
59# define AUX778076_FOLD_IMPL_NAME \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070060 NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_impl) \
Jeff Thompsona28eed82013-08-22 16:21:10 -070061 /**/
62
63# define AUX778076_FOLD_CHUNK_NAME \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070064 NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_chunk) \
Jeff Thompsona28eed82013-08-22 16:21:10 -070065 /**/
66
67namespace ndnboost { namespace mpl { namespace aux {
68
69/// forward declaration
70template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070071 NDNBOOST_MPL_AUX_NTTP_DECL(long, N)
Jeff Thompsona28eed82013-08-22 16:21:10 -070072 , typename First
73 , typename Last
74 , typename State
75 , typename BackwardOp
76 , typename ForwardOp
77 >
78struct AUX778076_FOLD_IMPL_NAME;
79
Jeff Thompson3d613fd2013-10-15 15:39:04 -070080#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
81 && !defined(NDNBOOST_MPL_CFG_NO_NONTYPE_TEMPLATE_PARTIAL_SPEC)
Jeff Thompsona28eed82013-08-22 16:21:10 -070082
Jeff Thompson3d613fd2013-10-15 15:39:04 -070083# define NDNBOOST_PP_ITERATION_PARAMS_1 \
84 (3,(0, NDNBOOST_MPL_LIMIT_UNROLLING, <ndnboost/mpl/aux_/reverse_fold_impl_body.hpp>))
85# include NDNBOOST_PP_ITERATE()
Jeff Thompsona28eed82013-08-22 16:21:10 -070086
Jeff Thompson3d613fd2013-10-15 15:39:04 -070087// implementation for N that exceeds NDNBOOST_MPL_LIMIT_UNROLLING
Jeff Thompsona28eed82013-08-22 16:21:10 -070088template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070089 NDNBOOST_MPL_AUX_NTTP_DECL(long, N)
Jeff Thompsona28eed82013-08-22 16:21:10 -070090 , 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700101 NDNBOOST_MPL_PP_REPEAT(
102 NDNBOOST_MPL_LIMIT_UNROLLING
Jeff Thompsona28eed82013-08-22 16:21:10 -0700103 , AUX778076_ITER_FOLD_FORWARD_STEP
104 , unused
105 )
106
107 typedef AUX778076_FOLD_IMPL_NAME<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700108 ( (N - NDNBOOST_MPL_LIMIT_UNROLLING) < 0 ? 0 : N - NDNBOOST_MPL_LIMIT_UNROLLING )
109 , NDNBOOST_PP_CAT(iter,NDNBOOST_MPL_LIMIT_UNROLLING)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700110 , Last
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700111 , NDNBOOST_PP_CAT(fwd_state,NDNBOOST_MPL_LIMIT_UNROLLING)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700112 , BackwardOp
113 , ForwardOp
114 > nested_chunk;
115
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700116 AUX778076_FIRST_BACKWARD_STATE_TYPEDEF(NDNBOOST_MPL_LIMIT_UNROLLING)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700117
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700118 NDNBOOST_MPL_PP_REPEAT(
119 NDNBOOST_MPL_LIMIT_UNROLLING
Jeff Thompsona28eed82013-08-22 16:21:10 -0700120 , AUX778076_ITER_FOLD_BACKWARD_STEP
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700121 , NDNBOOST_MPL_LIMIT_UNROLLING
Jeff Thompsona28eed82013-08-22 16:21:10 -0700122 )
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700168#else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsona28eed82013-08-22 16:21:10 -0700169
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700170template< NDNBOOST_MPL_AUX_NTTP_DECL(long, N) >
Jeff Thompsona28eed82013-08-22 16:21:10 -0700171struct AUX778076_FOLD_CHUNK_NAME;
172
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700173# define NDNBOOST_PP_ITERATION_PARAMS_1 \
174 (3,(0, NDNBOOST_MPL_LIMIT_UNROLLING, <ndnboost/mpl/aux_/reverse_fold_impl_body.hpp>))
175# include NDNBOOST_PP_ITERATE()
Jeff Thompsona28eed82013-08-22 16:21:10 -0700176
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700177// implementation for N that exceeds NDNBOOST_MPL_LIMIT_UNROLLING
178template< NDNBOOST_MPL_AUX_NTTP_DECL(long, N) >
Jeff Thompsona28eed82013-08-22 16:21:10 -0700179struct 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700193 NDNBOOST_MPL_PP_REPEAT(
194 NDNBOOST_MPL_LIMIT_UNROLLING
Jeff Thompsona28eed82013-08-22 16:21:10 -0700195 , AUX778076_ITER_FOLD_FORWARD_STEP
196 , unused
197 )
198
199 typedef AUX778076_FOLD_IMPL_NAME<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700200 ( (N - NDNBOOST_MPL_LIMIT_UNROLLING) < 0 ? 0 : N - NDNBOOST_MPL_LIMIT_UNROLLING )
201 , NDNBOOST_PP_CAT(iter,NDNBOOST_MPL_LIMIT_UNROLLING)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700202 , Last
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700203 , NDNBOOST_PP_CAT(fwd_state,NDNBOOST_MPL_LIMIT_UNROLLING)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700204 , BackwardOp
205 , ForwardOp
206 > nested_chunk;
207
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700208 AUX778076_FIRST_BACKWARD_STATE_TYPEDEF(NDNBOOST_MPL_LIMIT_UNROLLING)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700209
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700210 NDNBOOST_MPL_PP_REPEAT(
211 NDNBOOST_MPL_LIMIT_UNROLLING
Jeff Thompsona28eed82013-08-22 16:21:10 -0700212 , AUX778076_ITER_FOLD_BACKWARD_STEP
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700213 , NDNBOOST_MPL_LIMIT_UNROLLING
Jeff Thompsona28eed82013-08-22 16:21:10 -0700214 )
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 >
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700229struct NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step);
Jeff Thompsona28eed82013-08-22 16:21:10 -0700230
231template<
232 typename Last
233 , typename State
234 >
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700235struct NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_null_step)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700236{
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700255 , NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_null_step)<Last,State>
256 , NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step)<First,Last,State,BackwardOp,ForwardOp>
Jeff Thompsona28eed82013-08-22 16:21:10 -0700257 >::type res_;
258
259 typedef typename res_::state state;
260 typedef typename res_::iterator iterator;
261 };
262
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700263#if defined(NDNBOOST_MPL_CFG_MSVC_60_ETI_BUG)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700264 /// 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 >
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700280struct NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700281{
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<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700300 NDNBOOST_MPL_AUX_NTTP_DECL(long, N)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700301 , 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700313#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsona28eed82013-08-22 16:21:10 -0700314
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700329# define n_ NDNBOOST_PP_FRAME_ITERATION(1)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700330
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700331#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
332 && !defined(NDNBOOST_MPL_CFG_NO_NONTYPE_TEMPLATE_PARTIAL_SPEC)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700333
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700346 NDNBOOST_MPL_PP_REPEAT(
Jeff Thompsona28eed82013-08-22 16:21:10 -0700347 n_
348 , AUX778076_ITER_FOLD_FORWARD_STEP
349 , unused
350 )
351
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700352 typedef NDNBOOST_PP_CAT(fwd_state,n_) NDNBOOST_PP_CAT(bkwd_state,n_);
Jeff Thompsona28eed82013-08-22 16:21:10 -0700353
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700354 NDNBOOST_MPL_PP_REPEAT(
Jeff Thompsona28eed82013-08-22 16:21:10 -0700355 n_
356 , AUX778076_ITER_FOLD_BACKWARD_STEP
357 , n_
358 )
359
360 typedef bkwd_state0 state;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700361 typedef NDNBOOST_PP_CAT(iter,n_) iterator;
Jeff Thompsona28eed82013-08-22 16:21:10 -0700362};
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700380 NDNBOOST_MPL_PP_REPEAT(
Jeff Thompsona28eed82013-08-22 16:21:10 -0700381 n_
382 , AUX778076_ITER_FOLD_FORWARD_STEP
383 , unused
384 )
385
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700386 typedef NDNBOOST_PP_CAT(fwd_state,n_) NDNBOOST_PP_CAT(bkwd_state,n_);
Jeff Thompsona28eed82013-08-22 16:21:10 -0700387
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700388 NDNBOOST_MPL_PP_REPEAT(
Jeff Thompsona28eed82013-08-22 16:21:10 -0700389 n_
390 , AUX778076_ITER_FOLD_BACKWARD_STEP
391 , n_
392 )
393
394 typedef bkwd_state0 state;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700395 typedef NDNBOOST_PP_CAT(iter,n_) iterator;
Jeff Thompsona28eed82013-08-22 16:21:10 -0700396 };
397
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700398#if defined(NDNBOOST_MPL_CFG_MSVC_60_ETI_BUG)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700399 /// 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700408#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsona28eed82013-08-22 16:21:10 -0700409
410# undef n_
411
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700412#endif // NDNBOOST_PP_IS_ITERATING