segmented_fold_until.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*=============================================================================
  2. Copyright (c) 2011 Eric Niebler
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_FUSION_SEGMENTED_FOLD_UNTIL_HPP_INCLUDED)
  7. #define BOOST_FUSION_SEGMENTED_FOLD_UNTIL_HPP_INCLUDED
  8. #include <boost/type_traits/is_const.hpp>
  9. #include <boost/utility/enable_if.hpp>
  10. #include <boost/fusion/support/detail/segmented_fold_until_impl.hpp>
  11. #include <boost/fusion/view/iterator_range.hpp>
  12. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  13. #include <boost/fusion/sequence/intrinsic/end.hpp>
  14. #include <boost/fusion/sequence/intrinsic/empty.hpp>
  15. #include <boost/fusion/container/list/cons.hpp>
  16. namespace boost { namespace fusion
  17. {
  18. //auto segmented_fold_until(seq, state, fun)
  19. //{
  20. // return first(segmented_fold_until_impl(seq, state, nil_, fun));
  21. //}
  22. namespace result_of
  23. {
  24. template <typename Sequence, typename State, typename Fun>
  25. struct segmented_fold_until
  26. {
  27. typedef
  28. detail::segmented_fold_until_impl<
  29. Sequence
  30. , State
  31. , fusion::nil_
  32. , Fun
  33. >
  34. filter;
  35. typedef
  36. typename filter::type
  37. type;
  38. };
  39. }
  40. template <typename Sequence, typename State, typename Fun>
  41. typename
  42. lazy_disable_if<
  43. is_const<Sequence>
  44. , result_of::segmented_fold_until<Sequence, State, Fun>
  45. >::type
  46. segmented_fold_until(Sequence& seq, State const& state, Fun const& fun)
  47. {
  48. typedef
  49. typename result_of::segmented_fold_until<Sequence, State, Fun>::filter
  50. filter;
  51. return filter::call(seq, state, fusion::nil_(), fun);
  52. }
  53. template <typename Sequence, typename State, typename Fun>
  54. typename result_of::segmented_fold_until<Sequence const, State, Fun>::type
  55. segmented_fold_until(Sequence const& seq, State const& state, Fun const& fun)
  56. {
  57. typedef
  58. typename result_of::segmented_fold_until<Sequence const, State, Fun>::filter
  59. filter;
  60. return filter::call(seq, state, fusion::nil_(), fun);
  61. }
  62. }}
  63. #endif