segmented_for_each.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_FOR_EACH_HPP_INCLUDED)
  7. #define BOOST_FUSION_SEGMENTED_FOR_EACH_HPP_INCLUDED
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/mpl/bool.hpp>
  10. #include <boost/fusion/support/void.hpp>
  11. #include <boost/fusion/algorithm/iteration/for_each_fwd.hpp>
  12. #include <boost/fusion/support/segmented_fold_until.hpp>
  13. namespace boost { namespace fusion { namespace detail
  14. {
  15. template <typename Fun>
  16. struct segmented_for_each_fun
  17. {
  18. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  19. explicit segmented_for_each_fun(Fun& f)
  20. : fun(f)
  21. {}
  22. Fun& fun;
  23. template <typename Sequence, typename State, typename Context>
  24. struct apply
  25. {
  26. typedef void_ type;
  27. typedef mpl::true_ continue_type;
  28. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  29. static type call(Sequence& seq, State const&, Context const&, segmented_for_each_fun const& fun)
  30. {
  31. fusion::for_each(seq, fun.fun);
  32. return void_();
  33. }
  34. };
  35. };
  36. template <typename Sequence, typename F>
  37. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  38. inline void
  39. for_each(Sequence& seq, F& f, mpl::true_) // segmented implementation
  40. {
  41. fusion::segmented_fold_until(seq, void_(), segmented_for_each_fun<F>(f));
  42. }
  43. }}}
  44. #endif