blob: 67c4b9af06e81647adddd7cb7e4e696852c0c757 [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: 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/workaround.hpp>
21# include <ndnboost/mpl/aux_/config/ctps.hpp>
22# include <ndnboost/mpl/aux_/nttp_decl.hpp>
23# include <ndnboost/mpl/aux_/config/eti.hpp>
24
25# include <ndnboost/preprocessor/iterate.hpp>
26# include <ndnboost/preprocessor/dec.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_STEP(unused, i, unused2) \
32 typedef typename apply2< \
33 ForwardOp \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070034 , NDNBOOST_PP_CAT(state,i) \
35 , AUX778076_FOLD_IMPL_OP(NDNBOOST_PP_CAT(iter,i)) \
36 >::type NDNBOOST_PP_CAT(state,NDNBOOST_PP_INC(i)); \
37 typedef typename mpl::next<NDNBOOST_PP_CAT(iter,i)>::type \
38 NDNBOOST_PP_CAT(iter,NDNBOOST_PP_INC(i)); \
Jeff Thompsona28eed82013-08-22 16:21:10 -070039 /**/
40
41# define AUX778076_FOLD_IMPL_NAME \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070042 NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_impl) \
Jeff Thompsona28eed82013-08-22 16:21:10 -070043 /**/
44
45# define AUX778076_FOLD_CHUNK_NAME \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070046 NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_chunk) \
Jeff Thompsona28eed82013-08-22 16:21:10 -070047 /**/
48
49namespace ndnboost { namespace mpl { namespace aux {
50
51/// forward declaration
52template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070053 NDNBOOST_MPL_AUX_NTTP_DECL(int, N)
Jeff Thompsona28eed82013-08-22 16:21:10 -070054 , typename First
55 , typename Last
56 , typename State
57 , typename ForwardOp
58 >
59struct AUX778076_FOLD_IMPL_NAME;
60
Jeff Thompson3d613fd2013-10-15 15:39:04 -070061#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsona28eed82013-08-22 16:21:10 -070062
Jeff Thompson3d613fd2013-10-15 15:39:04 -070063# if !NDNBOOST_WORKAROUND(__BORLANDC__, < 0x600)
Jeff Thompsona28eed82013-08-22 16:21:10 -070064
Jeff Thompson3d613fd2013-10-15 15:39:04 -070065# define NDNBOOST_PP_ITERATION_PARAMS_1 \
66 (3,(0, NDNBOOST_MPL_LIMIT_UNROLLING, <ndnboost/mpl/aux_/fold_impl_body.hpp>))
67# include NDNBOOST_PP_ITERATE()
Jeff Thompsona28eed82013-08-22 16:21:10 -070068
Jeff Thompson3d613fd2013-10-15 15:39:04 -070069// implementation for N that exceeds NDNBOOST_MPL_LIMIT_UNROLLING
Jeff Thompsona28eed82013-08-22 16:21:10 -070070template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070071 NDNBOOST_MPL_AUX_NTTP_DECL(int, N)
Jeff Thompsona28eed82013-08-22 16:21:10 -070072 , typename First
73 , typename Last
74 , typename State
75 , typename ForwardOp
76 >
77struct AUX778076_FOLD_IMPL_NAME
78{
79 typedef AUX778076_FOLD_IMPL_NAME<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070080 NDNBOOST_MPL_LIMIT_UNROLLING
Jeff Thompsona28eed82013-08-22 16:21:10 -070081 , First
82 , Last
83 , State
84 , ForwardOp
85 > chunk_;
86
87 typedef AUX778076_FOLD_IMPL_NAME<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070088 ( (N - NDNBOOST_MPL_LIMIT_UNROLLING) < 0 ? 0 : N - NDNBOOST_MPL_LIMIT_UNROLLING )
Jeff Thompsona28eed82013-08-22 16:21:10 -070089 , 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
100template<
101 typename First
102 , typename Last
103 , typename State
104 , typename ForwardOp
105 >
106struct 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
117template<
118 typename Last
119 , typename State
120 , typename ForwardOp
121 >
122struct AUX778076_FOLD_IMPL_NAME<-1,Last,Last,State,ForwardOp>
123{
124 typedef State state;
125 typedef Last iterator;
126};
127
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700128# else // NDNBOOST_WORKAROUND(__BORLANDC__, < 0x600)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700129
130// Borland have some serious problems with the unrolled version, so
131// we always use a basic implementation
132template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700133 NDNBOOST_MPL_AUX_NTTP_DECL(int, N)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700134 , typename First
135 , typename Last
136 , typename State
137 , typename ForwardOp
138 >
139struct 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
154template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700155 NDNBOOST_MPL_AUX_NTTP_DECL(int, N)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700156 , typename Last
157 , typename State
158 , typename ForwardOp
159 >
160struct AUX778076_FOLD_IMPL_NAME<N,Last,Last,State,ForwardOp >
161{
162 typedef State state;
163 typedef Last iterator;
164 typedef state type;
165};
166
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700167# endif // NDNBOOST_WORKAROUND(__BORLANDC__, < 0x600)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700168
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700169#else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsona28eed82013-08-22 16:21:10 -0700170
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700171template< NDNBOOST_MPL_AUX_NTTP_DECL(int, N) >
Jeff Thompsona28eed82013-08-22 16:21:10 -0700172struct AUX778076_FOLD_CHUNK_NAME;
173
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700174# define NDNBOOST_PP_ITERATION_PARAMS_1 \
175 (3,(0, NDNBOOST_MPL_LIMIT_UNROLLING, <ndnboost/mpl/aux_/fold_impl_body.hpp>))
176# include NDNBOOST_PP_ITERATE()
Jeff Thompsona28eed82013-08-22 16:21:10 -0700177
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700178// implementation for N that exceeds NDNBOOST_MPL_LIMIT_UNROLLING
179template< NDNBOOST_MPL_AUX_NTTP_DECL(int, N) >
Jeff Thompsona28eed82013-08-22 16:21:10 -0700180struct 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<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700191 NDNBOOST_MPL_LIMIT_UNROLLING
Jeff Thompsona28eed82013-08-22 16:21:10 -0700192 , First
193 , Last
194 , State
195 , ForwardOp
196 > chunk_;
197
198 typedef AUX778076_FOLD_IMPL_NAME<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700199 ( (N - NDNBOOST_MPL_LIMIT_UNROLLING) < 0 ? 0 : N - NDNBOOST_MPL_LIMIT_UNROLLING )
Jeff Thompsona28eed82013-08-22 16:21:10 -0700200 , 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
212template<
213 typename First
214 , typename Last
215 , typename State
216 , typename ForwardOp
217 >
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700218struct NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step);
Jeff Thompsona28eed82013-08-22 16:21:10 -0700219
220template<
221 typename Last
222 , typename State
223 >
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700224struct NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_null_step)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700225{
226 typedef Last iterator;
227 typedef State state;
228};
229
230template<>
231struct 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700243 , NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_null_step)<Last,State>
244 , NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step)<First,Last,State,ForwardOp>
Jeff Thompsona28eed82013-08-22 16:21:10 -0700245 >::type res_;
246
247 typedef typename res_::state state;
248 typedef typename res_::iterator iterator;
249 };
250
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700251#if defined(NDNBOOST_MPL_CFG_MSVC_60_ETI_BUG)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700252 /// ETI workaround
253 template<> struct result_<int,int,int,int>
254 {
255 typedef int state;
256 typedef int iterator;
257 };
258#endif
259};
260
261template<
262 typename First
263 , typename Last
264 , typename State
265 , typename ForwardOp
266 >
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700267struct NDNBOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700268{
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
281template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700282 NDNBOOST_MPL_AUX_NTTP_DECL(int, N)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700283 , typename First
284 , typename Last
285 , typename State
286 , typename ForwardOp
287 >
288struct AUX778076_FOLD_IMPL_NAME
289 : AUX778076_FOLD_CHUNK_NAME<N>
290 ::template result_<First,Last,State,ForwardOp>
291{
292};
293
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700294#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsona28eed82013-08-22 16:21:10 -0700295
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700309# define n_ NDNBOOST_PP_FRAME_ITERATION(1)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700310
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700311#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700312
313template<
314 typename First
315 , typename Last
316 , typename State
317 , typename ForwardOp
318 >
319struct AUX778076_FOLD_IMPL_NAME<n_,First,Last,State,ForwardOp>
320{
321 typedef First iter0;
322 typedef State state0;
323
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700324 NDNBOOST_MPL_PP_REPEAT(n_, AUX778076_ITER_FOLD_STEP, unused)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700325
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700326 typedef NDNBOOST_PP_CAT(state,n_) state;
327 typedef NDNBOOST_PP_CAT(iter,n_) iterator;
Jeff Thompsona28eed82013-08-22 16:21:10 -0700328};
329
330#else
331
332template<> 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700345 NDNBOOST_MPL_PP_REPEAT(n_, AUX778076_ITER_FOLD_STEP, unused)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700346
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700347 typedef NDNBOOST_PP_CAT(state,n_) state;
348 typedef NDNBOOST_PP_CAT(iter,n_) iterator;
Jeff Thompsona28eed82013-08-22 16:21:10 -0700349 };
350
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700351#if defined(NDNBOOST_MPL_CFG_MSVC_60_ETI_BUG)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700352 /// ETI workaround
353 template<> struct result_<int,int,int,int>
354 {
355 typedef int state;
356 typedef int iterator;
357 };
358#endif
359};
360
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700361#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsona28eed82013-08-22 16:21:10 -0700362
363# undef n_
364
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700365#endif // NDNBOOST_PP_IS_ITERATING