segmented_begin_impl.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_BEGIN_IMPL_HPP_INCLUDED)
  7. #define BOOST_FUSION_SEGMENTED_BEGIN_IMPL_HPP_INCLUDED
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/type_traits/remove_const.hpp>
  10. #include <boost/fusion/container/list/cons_fwd.hpp>
  11. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  12. #include <boost/fusion/support/is_segmented.hpp>
  13. #include <boost/fusion/sequence/intrinsic/detail/segmented_end_impl.hpp>
  14. #include <boost/fusion/support/detail/segmented_fold_until_impl.hpp>
  15. namespace boost { namespace fusion
  16. {
  17. template <typename First, typename Last>
  18. struct iterator_range;
  19. }}
  20. namespace boost { namespace fusion { namespace detail
  21. {
  22. struct segmented_begin_fun
  23. {
  24. template <typename Sequence, typename State, typename Context>
  25. struct apply
  26. {
  27. typedef
  28. iterator_range<
  29. typename fusion::result_of::begin<Sequence>::type
  30. , typename fusion::result_of::end<Sequence>::type
  31. >
  32. range_type;
  33. typedef cons<range_type, Context> type;
  34. typedef mpl::false_ continue_type;
  35. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  36. static type call(Sequence& seq, State const&, Context const& context, segmented_begin_fun)
  37. {
  38. return type(range_type(fusion::begin(seq), fusion::end(seq)), context);
  39. }
  40. };
  41. };
  42. template <typename Sequence, typename Stack, bool IsSegmented = traits::is_segmented<Sequence>::type::value>
  43. struct segmented_begin_impl_aux
  44. {
  45. typedef
  46. segmented_end_impl<Sequence, Stack>
  47. end_impl;
  48. typedef
  49. segmented_fold_until_impl<
  50. Sequence
  51. , typename end_impl::type
  52. , Stack
  53. , segmented_begin_fun
  54. >
  55. fold_impl;
  56. typedef typename fold_impl::type type;
  57. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  58. static type call(Sequence& seq, Stack const& stack)
  59. {
  60. return fold_impl::call(seq, end_impl::call(seq, stack), stack, segmented_begin_fun());
  61. }
  62. };
  63. template <typename Sequence, typename Stack>
  64. struct segmented_begin_impl_aux<Sequence, Stack, false>
  65. {
  66. typedef typename result_of::begin<Sequence>::type begin_type;
  67. typedef typename result_of::end<Sequence>::type end_type;
  68. typedef iterator_range<begin_type, end_type> pair_type;
  69. typedef cons<pair_type, Stack> type;
  70. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  71. static type call(Sequence& seq, Stack stack)
  72. {
  73. return type(pair_type(fusion::begin(seq), fusion::end(seq)), stack);
  74. }
  75. };
  76. template <typename Sequence, typename Stack>
  77. struct segmented_begin_impl
  78. : segmented_begin_impl_aux<Sequence, Stack>
  79. {};
  80. }}}
  81. #endif