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.
14 // $Id: fold_impl_body.hpp 49267 2008-10-11 06:19:02Z agurtovoy $
15 // $Date: 2008-10-11 02:19:02 -0400 (Sat, 11 Oct 2008) $
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>
25 # include <boost/preprocessor/iterate.hpp>
26 # include <boost/preprocessor/dec.hpp>
27 # include <boost/preprocessor/cat.hpp>
29 // local macros, #undef-ined at the end of the header
31 # define AUX778076_ITER_FOLD_STEP(unused, i, unused2) \
32 typedef typename apply2< \
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)); \
41 # define AUX778076_FOLD_IMPL_NAME \
42 BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_impl) \
45 # define AUX778076_FOLD_CHUNK_NAME \
46 BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_chunk) \
49 namespace boost { namespace mpl { namespace aux {
51 /// forward declaration
53 BOOST_MPL_AUX_NTTP_DECL(int, N)
59 struct AUX778076_FOLD_IMPL_NAME;
61 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
63 # if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
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()
69 // implementation for N that exceeds BOOST_MPL_LIMIT_UNROLLING
71 BOOST_MPL_AUX_NTTP_DECL(int, N)
77 struct AUX778076_FOLD_IMPL_NAME
79 typedef AUX778076_FOLD_IMPL_NAME<
80 BOOST_MPL_LIMIT_UNROLLING
87 typedef AUX778076_FOLD_IMPL_NAME<
88 ( (N - BOOST_MPL_LIMIT_UNROLLING) < 0 ? 0 : N - BOOST_MPL_LIMIT_UNROLLING )
89 , typename chunk_::iterator
91 , typename chunk_::state
95 typedef typename res_::state state;
96 typedef typename res_::iterator iterator;
99 // fallback implementation for sequences of unknown size
106 struct AUX778076_FOLD_IMPL_NAME<-1,First,Last,State,ForwardOp>
107 : AUX778076_FOLD_IMPL_NAME<
109 , typename mpl::next<First>::type
111 , typename apply2<ForwardOp,State,AUX778076_FOLD_IMPL_OP(First)>::type
122 struct AUX778076_FOLD_IMPL_NAME<-1,Last,Last,State,ForwardOp>
125 typedef Last iterator;
128 # else // BOOST_WORKAROUND(__BORLANDC__, < 0x600)
130 // Borland have some serious problems with the unrolled version, so
131 // we always use a basic implementation
133 BOOST_MPL_AUX_NTTP_DECL(int, N)
139 struct AUX778076_FOLD_IMPL_NAME
141 typedef AUX778076_FOLD_IMPL_NAME<
143 , typename mpl::next<First>::type
145 , typename apply2<ForwardOp,State,AUX778076_FOLD_IMPL_OP(First)>::type
149 typedef typename res_::state state;
150 typedef typename res_::iterator iterator;
155 BOOST_MPL_AUX_NTTP_DECL(int, N)
160 struct AUX778076_FOLD_IMPL_NAME<N,Last,Last,State,ForwardOp >
163 typedef Last iterator;
167 # endif // BOOST_WORKAROUND(__BORLANDC__, < 0x600)
169 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
171 template< BOOST_MPL_AUX_NTTP_DECL(int, N) >
172 struct AUX778076_FOLD_CHUNK_NAME;
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()
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
190 typedef AUX778076_FOLD_IMPL_NAME<
191 BOOST_MPL_LIMIT_UNROLLING
198 typedef AUX778076_FOLD_IMPL_NAME<
199 ( (N - BOOST_MPL_LIMIT_UNROLLING) < 0 ? 0 : N - BOOST_MPL_LIMIT_UNROLLING )
200 , typename chunk_::iterator
202 , typename chunk_::state
206 typedef typename res_::state state;
207 typedef typename res_::iterator iterator;
211 // fallback implementation for sequences of unknown size
218 struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step);
224 struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_null_step)
226 typedef Last iterator;
231 struct AUX778076_FOLD_CHUNK_NAME<-1>
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>
247 typedef typename res_::state state;
248 typedef typename res_::iterator iterator;
251 #if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
253 template<> struct result_<int,int,int,int>
256 typedef int iterator;
267 struct BOOST_PP_CAT(AUX778076_FOLD_IMPL_NAME_PREFIX,_step)
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
273 , typename apply2<ForwardOp,State,AUX778076_FOLD_IMPL_OP(First)>::type
277 typedef typename chunk_::state state;
278 typedef typename chunk_::iterator iterator;
282 BOOST_MPL_AUX_NTTP_DECL(int, N)
288 struct AUX778076_FOLD_IMPL_NAME
289 : AUX778076_FOLD_CHUNK_NAME<N>
290 ::template result_<First,Last,State,ForwardOp>
294 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
298 # undef AUX778076_FOLD_IMPL_NAME
299 # undef AUX778076_FOLD_CHUNK_NAME
300 # undef AUX778076_ITER_FOLD_STEP
302 #undef AUX778076_FOLD_IMPL_OP
303 #undef AUX778076_FOLD_IMPL_NAME_PREFIX
309 # define n_ BOOST_PP_FRAME_ITERATION(1)
311 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
319 struct AUX778076_FOLD_IMPL_NAME<n_,First,Last,State,ForwardOp>
322 typedef State state0;
324 BOOST_MPL_PP_REPEAT(n_, AUX778076_ITER_FOLD_STEP, unused)
326 typedef BOOST_PP_CAT(state,n_) state;
327 typedef BOOST_PP_CAT(iter,n_) iterator;
332 template<> struct AUX778076_FOLD_CHUNK_NAME<n_>
343 typedef State state0;
345 BOOST_MPL_PP_REPEAT(n_, AUX778076_ITER_FOLD_STEP, unused)
347 typedef BOOST_PP_CAT(state,n_) state;
348 typedef BOOST_PP_CAT(iter,n_) iterator;
351 #if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
353 template<> struct result_<int,int,int,int>
356 typedef int iterator;
361 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
365 #endif // BOOST_PP_IS_ITERATING