segmented_fold.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_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. #ifdef _MSC_VER
  15. # pragma warning(push)
  16. # pragma warning(disable: 4512) // assignment operator could not be generated.
  17. #endif
  18. template <typename Fun>
  19. struct segmented_fold_fun
  20. {
  21. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  22. explicit segmented_fold_fun(Fun const& f)
  23. : fun(f)
  24. {}
  25. Fun const& fun;
  26. template <typename Sequence, typename State, typename Context>
  27. struct apply
  28. {
  29. typedef typename result_of::fold<Sequence, State, Fun>::type type;
  30. typedef mpl::true_ continue_type;
  31. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  32. static type call(Sequence& seq, State const& state, Context const&, segmented_fold_fun const& fun)
  33. {
  34. return fusion::fold(seq, state, fun.fun);
  35. }
  36. };
  37. };
  38. #ifdef _MSC_VER
  39. # pragma warning(pop)
  40. #endif
  41. // The default implementation of this lives in detail/fold.hpp
  42. template <typename Sequence, typename State, typename Fun, bool IsSequence, bool IsSegmented>
  43. struct result_of_fold;
  44. template <typename Sequence, typename State, typename Fun>
  45. struct result_of_fold<Sequence, State, Fun, true, true>
  46. {
  47. typedef
  48. typename result_of::segmented_fold_until<
  49. Sequence,
  50. State,
  51. segmented_fold_fun<Fun>
  52. >::type
  53. type;
  54. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  55. static type call(Sequence& seq, State& state, Fun& fun)
  56. {
  57. return fusion::segmented_fold_until(seq, state, segmented_fold_fun<Fun>(fun));
  58. }
  59. };
  60. }}}
  61. #endif