segmented_fold_until.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/fusion/support/config.hpp>
  9. #include <boost/type_traits/is_const.hpp>
  10. #include <boost/utility/enable_if.hpp>
  11. #include <boost/fusion/support/detail/segmented_fold_until_impl.hpp>
  12. namespace boost { namespace fusion
  13. {
  14. //auto segmented_fold_until(seq, state, fun)
  15. //{
  16. // return first(segmented_fold_until_impl(seq, state, nil_, fun));
  17. //}
  18. namespace result_of
  19. {
  20. template <typename Sequence, typename State, typename Fun>
  21. struct segmented_fold_until
  22. {
  23. typedef
  24. detail::segmented_fold_until_impl<
  25. Sequence
  26. , State
  27. , fusion::nil_
  28. , Fun
  29. >
  30. filter;
  31. typedef
  32. typename filter::type
  33. type;
  34. };
  35. }
  36. template <typename Sequence, typename State, typename Fun>
  37. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  38. inline typename
  39. lazy_disable_if<
  40. is_const<Sequence>
  41. , result_of::segmented_fold_until<Sequence, State, Fun>
  42. >::type
  43. segmented_fold_until(Sequence& seq, State const& state, Fun const& fun)
  44. {
  45. typedef
  46. typename result_of::segmented_fold_until<Sequence, State, Fun>::filter
  47. filter;
  48. return filter::call(seq, state, fusion::nil_(), fun);
  49. }
  50. template <typename Sequence, typename State, typename Fun>
  51. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  52. inline typename result_of::segmented_fold_until<Sequence const, State, Fun>::type
  53. segmented_fold_until(Sequence const& seq, State const& state, Fun const& fun)
  54. {
  55. typedef
  56. typename result_of::segmented_fold_until<Sequence const, State, Fun>::filter
  57. filter;
  58. return filter::call(seq, state, fusion::nil_(), fun);
  59. }
  60. }}
  61. #endif