segmented_fold.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_FOLD_S_HPP_INCLUDED)
  7. #define BOOST_FUSION_FOLD_S_HPP_INCLUDED
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/algorithm/iteration/fold_fwd.hpp>
  10. #include <boost/fusion/support/segmented_fold_until.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. namespace boost { namespace fusion { namespace detail
  13. {
  14. template <typename Fun>
  15. struct segmented_fold_fun
  16. {
  17. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  18. explicit segmented_fold_fun(Fun const& f)
  19. : fun(f)
  20. {}
  21. Fun const& fun;
  22. template <typename Sequence, typename State, typename Context>
  23. struct apply
  24. {
  25. typedef typename result_of::fold<Sequence, State, Fun>::type type;
  26. typedef mpl::true_ continue_type;
  27. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  28. static type call(Sequence& seq, State const& state, Context const&, segmented_fold_fun const& fun)
  29. {
  30. return fusion::fold(seq, state, fun.fun);
  31. }
  32. };
  33. };
  34. // The default implementation of this lives in detail/fold.hpp
  35. template <typename Sequence, typename State, typename Fun, bool IsSequence, bool IsSegmented>
  36. struct result_of_fold;
  37. template <typename Sequence, typename State, typename Fun>
  38. struct result_of_fold<Sequence, State, Fun, true, true>
  39. {
  40. typedef
  41. typename result_of::segmented_fold_until<
  42. Sequence,
  43. State,
  44. segmented_fold_fun<Fun>
  45. >::type
  46. type;
  47. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  48. static type call(Sequence& seq, State& state, Fun& fun)
  49. {
  50. return fusion::segmented_fold_until(seq, state, segmented_fold_fun<Fun>(fun));
  51. }
  52. };
  53. }}}
  54. #endif