iter_fold_if_impl.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #ifndef BOOST_MPL_AUX_ITER_FOLD_IF_IMPL_HPP_INCLUDED
  2. #define BOOST_MPL_AUX_ITER_FOLD_IF_IMPL_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2001-2004
  4. // Copyright David Abrahams 2001-2002
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/mpl for documentation.
  11. // $Id$
  12. // $Date$
  13. // $Revision$
  14. #if !defined(BOOST_MPL_PREPROCESSING_MODE)
  15. # include <boost/mpl/identity.hpp>
  16. # include <boost/mpl/next.hpp>
  17. # include <boost/mpl/if.hpp>
  18. # include <boost/mpl/apply.hpp>
  19. # include <boost/mpl/aux_/value_wknd.hpp>
  20. #endif
  21. #include <boost/mpl/aux_/config/use_preprocessed.hpp>
  22. #if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
  23. && !defined(BOOST_MPL_PREPROCESSING_MODE)
  24. # define BOOST_MPL_PREPROCESSED_HEADER iter_fold_if_impl.hpp
  25. # include <boost/mpl/aux_/include_preprocessed.hpp>
  26. #else
  27. # include <boost/mpl/limits/unrolling.hpp>
  28. # include <boost/preprocessor/arithmetic/sub.hpp>
  29. # include <boost/preprocessor/repeat.hpp>
  30. # include <boost/preprocessor/inc.hpp>
  31. # include <boost/preprocessor/dec.hpp>
  32. # include <boost/preprocessor/cat.hpp>
  33. namespace boost { namespace mpl { namespace aux {
  34. template< typename Iterator, typename State >
  35. struct iter_fold_if_null_step
  36. {
  37. typedef State state;
  38. typedef Iterator iterator;
  39. };
  40. template< bool >
  41. struct iter_fold_if_step_impl
  42. {
  43. template<
  44. typename Iterator
  45. , typename State
  46. , typename StateOp
  47. , typename IteratorOp
  48. >
  49. struct result_
  50. {
  51. typedef typename apply2<StateOp,State,Iterator>::type state;
  52. typedef typename IteratorOp::type iterator;
  53. };
  54. };
  55. template<>
  56. struct iter_fold_if_step_impl<false>
  57. {
  58. template<
  59. typename Iterator
  60. , typename State
  61. , typename StateOp
  62. , typename IteratorOp
  63. >
  64. struct result_
  65. {
  66. typedef State state;
  67. typedef Iterator iterator;
  68. };
  69. };
  70. // agurt, 25/jun/02: MSVC 6.5 workaround, had to get rid of inheritance
  71. // here and in 'iter_fold_if_backward_step', because sometimes it interfered
  72. // with the "early template instantiation bug" in _really_ ugly ways
  73. template<
  74. typename Iterator
  75. , typename State
  76. , typename ForwardOp
  77. , typename Predicate
  78. >
  79. struct iter_fold_if_forward_step
  80. {
  81. typedef typename apply2<Predicate,State,Iterator>::type not_last;
  82. typedef typename iter_fold_if_step_impl<
  83. BOOST_MPL_AUX_MSVC_VALUE_WKND(not_last)::value
  84. >::template result_< Iterator,State,ForwardOp,mpl::next<Iterator> > impl_;
  85. typedef typename impl_::state state;
  86. typedef typename impl_::iterator iterator;
  87. };
  88. template<
  89. typename Iterator
  90. , typename State
  91. , typename BackwardOp
  92. , typename Predicate
  93. >
  94. struct iter_fold_if_backward_step
  95. {
  96. typedef typename apply2<Predicate,State,Iterator>::type not_last;
  97. typedef typename iter_fold_if_step_impl<
  98. BOOST_MPL_AUX_MSVC_VALUE_WKND(not_last)::value
  99. >::template result_< Iterator,State,BackwardOp,identity<Iterator> > impl_;
  100. typedef typename impl_::state state;
  101. typedef typename impl_::iterator iterator;
  102. };
  103. // local macros, #undef-ined at the end of the header
  104. # define AUX_ITER_FOLD_FORWARD_STEP(unused, i, unused2) \
  105. typedef iter_fold_if_forward_step< \
  106. typename BOOST_PP_CAT(forward_step,i)::iterator \
  107. , typename BOOST_PP_CAT(forward_step,i)::state \
  108. , ForwardOp \
  109. , ForwardPredicate \
  110. > BOOST_PP_CAT(forward_step, BOOST_PP_INC(i)); \
  111. /**/
  112. # define AUX_ITER_FOLD_BACKWARD_STEP_FUNC(i) \
  113. typedef iter_fold_if_backward_step< \
  114. typename BOOST_PP_CAT(forward_step,BOOST_PP_DEC(i))::iterator \
  115. , typename BOOST_PP_CAT(backward_step,i)::state \
  116. , BackwardOp \
  117. , BackwardPredicate \
  118. > BOOST_PP_CAT(backward_step,BOOST_PP_DEC(i)); \
  119. /**/
  120. # define AUX_ITER_FOLD_BACKWARD_STEP(unused, i, unused2) \
  121. AUX_ITER_FOLD_BACKWARD_STEP_FUNC( \
  122. BOOST_PP_SUB_D(1,BOOST_MPL_LIMIT_UNROLLING,i) \
  123. ) \
  124. /**/
  125. # define AUX_LAST_FORWARD_STEP \
  126. BOOST_PP_CAT(forward_step, BOOST_MPL_LIMIT_UNROLLING) \
  127. /**/
  128. # define AUX_LAST_BACKWARD_STEP \
  129. BOOST_PP_CAT(backward_step, BOOST_MPL_LIMIT_UNROLLING) \
  130. /**/
  131. template<
  132. typename Iterator
  133. , typename State
  134. , typename ForwardOp
  135. , typename ForwardPredicate
  136. , typename BackwardOp
  137. , typename BackwardPredicate
  138. >
  139. struct iter_fold_if_impl
  140. {
  141. private:
  142. typedef iter_fold_if_null_step<Iterator,State> forward_step0;
  143. BOOST_PP_REPEAT(
  144. BOOST_MPL_LIMIT_UNROLLING
  145. , AUX_ITER_FOLD_FORWARD_STEP
  146. , unused
  147. )
  148. typedef typename if_<
  149. typename AUX_LAST_FORWARD_STEP::not_last
  150. , iter_fold_if_impl<
  151. typename AUX_LAST_FORWARD_STEP::iterator
  152. , typename AUX_LAST_FORWARD_STEP::state
  153. , ForwardOp
  154. , ForwardPredicate
  155. , BackwardOp
  156. , BackwardPredicate
  157. >
  158. , iter_fold_if_null_step<
  159. typename AUX_LAST_FORWARD_STEP::iterator
  160. , typename AUX_LAST_FORWARD_STEP::state
  161. >
  162. >::type AUX_LAST_BACKWARD_STEP;
  163. BOOST_PP_REPEAT(
  164. BOOST_MPL_LIMIT_UNROLLING
  165. , AUX_ITER_FOLD_BACKWARD_STEP
  166. , unused
  167. )
  168. public:
  169. typedef typename backward_step0::state state;
  170. typedef typename AUX_LAST_BACKWARD_STEP::iterator iterator;
  171. };
  172. # undef AUX_LAST_BACKWARD_STEP
  173. # undef AUX_LAST_FORWARD_STEP
  174. # undef AUX_ITER_FOLD_BACKWARD_STEP
  175. # undef AUX_ITER_FOLD_BACKWARD_STEP_FUNC
  176. # undef AUX_ITER_FOLD_FORWARD_STEP
  177. }}}
  178. #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
  179. #endif // BOOST_MPL_AUX_ITER_FOLD_IF_IMPL_HPP_INCLUDED