2 // NO INCLUDE GUARDS, THE HEADER IS INTENDED FOR MULTIPLE INCLUSION!
4 #if !defined(BOOST_PP_IS_ITERATING)
6 // Copyright Aleksey Gurtovoy 2000-2004
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)
12 // See http://www.boost.org/libs/mpl for documentation.
18 # include <boost/mpl/limits/unrolling.hpp>
19 # include <boost/mpl/aux_/preprocessor/repeat.hpp>
20 # include <boost/mpl/aux_/config/ctps.hpp>
21 # include <boost/mpl/aux_/nttp_decl.hpp>
23 # include <boost/preprocessor/arithmetic/sub.hpp>
24 # include <boost/preprocessor/iterate.hpp>
25 # include <boost/preprocessor/dec.hpp>
26 # include <boost/preprocessor/inc.hpp>
27 # include <boost/preprocessor/cat.hpp>
29 // local macros, #undef-ined at the end of the header
31 # define AUX778076_ITER_FOLD_FORWARD_STEP(unused, n_, unused2) \
32 typedef typename apply2< \
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_)); \
41 # define AUX778076_ITER_FOLD_BACKWARD_STEP_FUNC(n_) \
42 typedef typename apply2< \
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_)); \
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_) \
55 # define AUX778076_FIRST_BACKWARD_STATE_TYPEDEF(n_) \
56 typedef typename nested_chunk::state BOOST_PP_CAT(bkwd_state,n_);
59 # define AUX778076_FOLD_IMPL_NAME \
60 BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_impl) \
63 # define AUX778076_FOLD_CHUNK_NAME \
64 BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_chunk) \
67 namespace boost { namespace mpl { namespace aux {
69 /// forward declaration
71 BOOST_MPL_AUX_NTTP_DECL(long, N)
78 struct AUX778076_FOLD_IMPL_NAME;
80 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
81 && !defined(BOOST_MPL_CFG_NO_NONTYPE_TEMPLATE_PARTIAL_SPEC)
83 # define BOOST_PP_ITERATION_PARAMS_1 \
84 (3,(0, BOOST_MPL_LIMIT_UNROLLING, <boost/mpl/aux_/reverse_fold_impl_body.hpp>))
85 # include BOOST_PP_ITERATE()
87 // implementation for N that exceeds BOOST_MPL_LIMIT_UNROLLING
89 BOOST_MPL_AUX_NTTP_DECL(long, N)
96 struct AUX778076_FOLD_IMPL_NAME
99 typedef State fwd_state0;
102 BOOST_MPL_LIMIT_UNROLLING
103 , AUX778076_ITER_FOLD_FORWARD_STEP
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)
111 , BOOST_PP_CAT(fwd_state,BOOST_MPL_LIMIT_UNROLLING)
116 AUX778076_FIRST_BACKWARD_STATE_TYPEDEF(BOOST_MPL_LIMIT_UNROLLING)
119 BOOST_MPL_LIMIT_UNROLLING
120 , AUX778076_ITER_FOLD_BACKWARD_STEP
121 , BOOST_MPL_LIMIT_UNROLLING
124 typedef bkwd_state0 state;
125 typedef typename nested_chunk::iterator iterator;
128 // fallback implementation for sequences of unknown size
133 , typename BackwardOp
136 struct AUX778076_FOLD_IMPL_NAME<-1,First,Last,State,BackwardOp,ForwardOp>
138 typedef AUX778076_FOLD_IMPL_NAME<
140 , typename mpl::next<First>::type
142 , typename apply2<ForwardOp,State,AUX778076_FOLD_IMPL_OP(First)>::type
147 typedef typename apply2<
149 , typename nested_step::state
150 , AUX778076_FOLD_IMPL_OP(First)
153 typedef typename nested_step::iterator iterator;
159 , typename BackwardOp
162 struct AUX778076_FOLD_IMPL_NAME<-1,Last,Last,State,BackwardOp,ForwardOp>
165 typedef Last iterator;
168 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
170 template< BOOST_MPL_AUX_NTTP_DECL(long, N) >
171 struct AUX778076_FOLD_CHUNK_NAME;
173 # define BOOST_PP_ITERATION_PARAMS_1 \
174 (3,(0, BOOST_MPL_LIMIT_UNROLLING, <boost/mpl/aux_/reverse_fold_impl_body.hpp>))
175 # include BOOST_PP_ITERATE()
177 // implementation for N that exceeds BOOST_MPL_LIMIT_UNROLLING
178 template< BOOST_MPL_AUX_NTTP_DECL(long, N) >
179 struct AUX778076_FOLD_CHUNK_NAME
185 , typename BackwardOp
191 typedef State fwd_state0;
194 BOOST_MPL_LIMIT_UNROLLING
195 , AUX778076_ITER_FOLD_FORWARD_STEP
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)
203 , BOOST_PP_CAT(fwd_state,BOOST_MPL_LIMIT_UNROLLING)
208 AUX778076_FIRST_BACKWARD_STATE_TYPEDEF(BOOST_MPL_LIMIT_UNROLLING)
211 BOOST_MPL_LIMIT_UNROLLING
212 , AUX778076_ITER_FOLD_BACKWARD_STEP
213 , BOOST_MPL_LIMIT_UNROLLING
216 typedef bkwd_state0 state;
217 typedef typename nested_chunk::iterator iterator;
221 // fallback implementation for sequences of unknown size
226 , typename BackwardOp
229 struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step);
235 struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_null_step)
237 typedef Last iterator;
242 struct AUX778076_FOLD_CHUNK_NAME<-1>
248 , typename BackwardOp
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>
259 typedef typename res_::state state;
260 typedef typename res_::iterator iterator;
263 #if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
265 template<> struct result_<int,int,int,int,int>
268 typedef int iterator;
277 , typename BackwardOp
280 struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step)
282 typedef AUX778076_FOLD_CHUNK_NAME<-1>::template result_<
283 typename mpl::next<First>::type
285 , typename apply2<ForwardOp,State,AUX778076_FOLD_IMPL_OP(First)>::type
290 typedef typename apply2<
292 , typename nested_step::state
293 , AUX778076_FOLD_IMPL_OP(First)
296 typedef typename nested_step::iterator iterator;
300 BOOST_MPL_AUX_NTTP_DECL(long, N)
304 , typename BackwardOp
307 struct AUX778076_FOLD_IMPL_NAME
308 : AUX778076_FOLD_CHUNK_NAME<N>
309 ::template result_<First,Last,State,BackwardOp,ForwardOp>
313 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
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
322 #undef AUX778076_FOLD_IMPL_OP
323 #undef AUX778076_FOLD_IMPL_NAME_PREFIX
329 # define n_ BOOST_PP_FRAME_ITERATION(1)
331 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
332 && !defined(BOOST_MPL_CFG_NO_NONTYPE_TEMPLATE_PARTIAL_SPEC)
338 , typename BackwardOp
341 struct AUX778076_FOLD_IMPL_NAME<n_,First,Last,State,BackwardOp,ForwardOp>
344 typedef State fwd_state0;
348 , AUX778076_ITER_FOLD_FORWARD_STEP
352 typedef BOOST_PP_CAT(fwd_state,n_) BOOST_PP_CAT(bkwd_state,n_);
356 , AUX778076_ITER_FOLD_BACKWARD_STEP
360 typedef bkwd_state0 state;
361 typedef BOOST_PP_CAT(iter,n_) iterator;
366 template<> struct AUX778076_FOLD_CHUNK_NAME<n_>
372 , typename BackwardOp
378 typedef State fwd_state0;
382 , AUX778076_ITER_FOLD_FORWARD_STEP
386 typedef BOOST_PP_CAT(fwd_state,n_) BOOST_PP_CAT(bkwd_state,n_);
390 , AUX778076_ITER_FOLD_BACKWARD_STEP
394 typedef bkwd_state0 state;
395 typedef BOOST_PP_CAT(iter,n_) iterator;
398 #if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
400 template<> struct result_<int,int,int,int,int>
403 typedef int iterator;
408 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
412 #endif // BOOST_PP_IS_ITERATING