iter_fold_if.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef BOOST_MPL_ITER_FOLD_IF_HPP_INCLUDED
  2. #define BOOST_MPL_ITER_FOLD_IF_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2003-2004
  4. // Copyright Eric Friedman 2003
  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. #include <boost/mpl/begin_end.hpp>
  15. #include <boost/mpl/logical.hpp>
  16. #include <boost/mpl/always.hpp>
  17. #include <boost/mpl/eval_if.hpp>
  18. #include <boost/mpl/if.hpp>
  19. #include <boost/mpl/pair.hpp>
  20. #include <boost/mpl/apply.hpp>
  21. #include <boost/mpl/aux_/iter_fold_if_impl.hpp>
  22. #include <boost/mpl/aux_/na_spec.hpp>
  23. #include <boost/mpl/aux_/lambda_support.hpp>
  24. #include <boost/mpl/aux_/config/forwarding.hpp>
  25. #include <boost/mpl/aux_/config/workaround.hpp>
  26. #include <boost/type_traits/is_same.hpp>
  27. namespace boost { namespace mpl {
  28. namespace aux {
  29. template< typename Predicate, typename LastIterator >
  30. struct iter_fold_if_pred
  31. {
  32. template< typename State, typename Iterator > struct apply
  33. #if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING)
  34. : and_<
  35. not_< is_same<Iterator,LastIterator> >
  36. , apply1<Predicate,Iterator>
  37. >
  38. {
  39. #else
  40. {
  41. typedef and_<
  42. not_< is_same<Iterator,LastIterator> >
  43. , apply1<Predicate,Iterator>
  44. > type;
  45. #endif
  46. };
  47. };
  48. } // namespace aux
  49. template<
  50. typename BOOST_MPL_AUX_NA_PARAM(Sequence)
  51. , typename BOOST_MPL_AUX_NA_PARAM(State)
  52. , typename BOOST_MPL_AUX_NA_PARAM(ForwardOp)
  53. , typename BOOST_MPL_AUX_NA_PARAM(ForwardPredicate)
  54. , typename BOOST_MPL_AUX_NA_PARAM(BackwardOp)
  55. , typename BOOST_MPL_AUX_NA_PARAM(BackwardPredicate)
  56. >
  57. struct iter_fold_if
  58. {
  59. typedef typename begin<Sequence>::type first_;
  60. typedef typename end<Sequence>::type last_;
  61. typedef typename eval_if<
  62. is_na<BackwardPredicate>
  63. , if_< is_na<BackwardOp>, always<false_>, always<true_> >
  64. , identity<BackwardPredicate>
  65. >::type backward_pred_;
  66. // cwpro8 doesn't like 'cut-off' type here (use typedef instead)
  67. #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) && !BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))
  68. struct result_ :
  69. #else
  70. typedef
  71. #endif
  72. aux::iter_fold_if_impl<
  73. first_
  74. , State
  75. , ForwardOp
  76. , protect< aux::iter_fold_if_pred< ForwardPredicate,last_ > >
  77. , BackwardOp
  78. , backward_pred_
  79. >
  80. #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) && !BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))
  81. { };
  82. #else
  83. result_;
  84. #endif
  85. public:
  86. typedef pair<
  87. typename result_::state
  88. , typename result_::iterator
  89. > type;
  90. BOOST_MPL_AUX_LAMBDA_SUPPORT(
  91. 6
  92. , iter_fold_if
  93. , (Sequence,State,ForwardOp,ForwardPredicate,BackwardOp,BackwardPredicate)
  94. )
  95. };
  96. BOOST_MPL_AUX_NA_SPEC(6, iter_fold_if)
  97. }}
  98. #endif // BOOST_MPL_ITER_FOLD_IF_HPP_INCLUDED