2 #ifndef BOOST_MPL_AUX_ITER_FOLD_IF_IMPL_HPP_INCLUDED
3 #define BOOST_MPL_AUX_ITER_FOLD_IF_IMPL_HPP_INCLUDED
5 // Copyright Aleksey Gurtovoy 2001-2004
6 // Copyright David Abrahams 2001-2002
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 #if !defined(BOOST_MPL_PREPROCESSING_MODE)
19 # include <boost/mpl/identity.hpp>
20 # include <boost/mpl/next.hpp>
21 # include <boost/mpl/if.hpp>
22 # include <boost/mpl/apply.hpp>
23 # include <boost/mpl/aux_/value_wknd.hpp>
26 #include <boost/mpl/aux_/config/use_preprocessed.hpp>
28 #if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
29 && !defined(BOOST_MPL_PREPROCESSING_MODE)
31 # define BOOST_MPL_PREPROCESSED_HEADER iter_fold_if_impl.hpp
32 # include <boost/mpl/aux_/include_preprocessed.hpp>
36 # include <boost/mpl/limits/unrolling.hpp>
37 # include <boost/preprocessor/arithmetic/sub.hpp>
38 # include <boost/preprocessor/repeat.hpp>
39 # include <boost/preprocessor/inc.hpp>
40 # include <boost/preprocessor/dec.hpp>
41 # include <boost/preprocessor/cat.hpp>
43 namespace boost { namespace mpl { namespace aux {
45 template< typename Iterator, typename State >
46 struct iter_fold_if_null_step
49 typedef Iterator iterator;
53 struct iter_fold_if_step_impl
63 typedef typename apply2<StateOp,State,Iterator>::type state;
64 typedef typename IteratorOp::type iterator;
69 struct iter_fold_if_step_impl<false>
80 typedef Iterator iterator;
84 // agurt, 25/jun/02: MSVC 6.5 workaround, had to get rid of inheritance
85 // here and in 'iter_fold_if_backward_step', because sometimes it interfered
86 // with the "early template instantiation bug" in _really_ ugly ways
93 struct iter_fold_if_forward_step
95 typedef typename apply2<Predicate,State,Iterator>::type not_last;
96 typedef typename iter_fold_if_step_impl<
97 BOOST_MPL_AUX_MSVC_VALUE_WKND(not_last)::value
98 >::template result_< Iterator,State,ForwardOp,mpl::next<Iterator> > impl_;
100 typedef typename impl_::state state;
101 typedef typename impl_::iterator iterator;
107 , typename BackwardOp
110 struct iter_fold_if_backward_step
112 typedef typename apply2<Predicate,State,Iterator>::type not_last;
113 typedef typename iter_fold_if_step_impl<
114 BOOST_MPL_AUX_MSVC_VALUE_WKND(not_last)::value
115 >::template result_< Iterator,State,BackwardOp,identity<Iterator> > impl_;
117 typedef typename impl_::state state;
118 typedef typename impl_::iterator iterator;
122 // local macros, #undef-ined at the end of the header
124 # define AUX_ITER_FOLD_FORWARD_STEP(unused, i, unused2) \
125 typedef iter_fold_if_forward_step< \
126 typename BOOST_PP_CAT(forward_step,i)::iterator \
127 , typename BOOST_PP_CAT(forward_step,i)::state \
130 > BOOST_PP_CAT(forward_step, BOOST_PP_INC(i)); \
133 # define AUX_ITER_FOLD_BACKWARD_STEP_FUNC(i) \
134 typedef iter_fold_if_backward_step< \
135 typename BOOST_PP_CAT(forward_step,BOOST_PP_DEC(i))::iterator \
136 , typename BOOST_PP_CAT(backward_step,i)::state \
138 , BackwardPredicate \
139 > BOOST_PP_CAT(backward_step,BOOST_PP_DEC(i)); \
142 # define AUX_ITER_FOLD_BACKWARD_STEP(unused, i, unused2) \
143 AUX_ITER_FOLD_BACKWARD_STEP_FUNC( \
144 BOOST_PP_SUB_D(1,BOOST_MPL_LIMIT_UNROLLING,i) \
148 # define AUX_LAST_FORWARD_STEP \
149 BOOST_PP_CAT(forward_step, BOOST_MPL_LIMIT_UNROLLING) \
152 # define AUX_LAST_BACKWARD_STEP \
153 BOOST_PP_CAT(backward_step, BOOST_MPL_LIMIT_UNROLLING) \
160 , typename ForwardPredicate
161 , typename BackwardOp
162 , typename BackwardPredicate
164 struct iter_fold_if_impl
167 typedef iter_fold_if_null_step<Iterator,State> forward_step0;
169 BOOST_MPL_LIMIT_UNROLLING
170 , AUX_ITER_FOLD_FORWARD_STEP
174 typedef typename if_<
175 typename AUX_LAST_FORWARD_STEP::not_last
177 typename AUX_LAST_FORWARD_STEP::iterator
178 , typename AUX_LAST_FORWARD_STEP::state
184 , iter_fold_if_null_step<
185 typename AUX_LAST_FORWARD_STEP::iterator
186 , typename AUX_LAST_FORWARD_STEP::state
188 >::type AUX_LAST_BACKWARD_STEP;
191 BOOST_MPL_LIMIT_UNROLLING
192 , AUX_ITER_FOLD_BACKWARD_STEP
197 typedef typename backward_step0::state state;
198 typedef typename AUX_LAST_BACKWARD_STEP::iterator iterator;
201 # undef AUX_LAST_BACKWARD_STEP
202 # undef AUX_LAST_FORWARD_STEP
203 # undef AUX_ITER_FOLD_BACKWARD_STEP
204 # undef AUX_ITER_FOLD_BACKWARD_STEP_FUNC
205 # undef AUX_ITER_FOLD_FORWARD_STEP
209 #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
210 #endif // BOOST_MPL_AUX_ITER_FOLD_IF_IMPL_HPP_INCLUDED