segmented_iterator.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_ITERATOR_SEGMENTED_ITERATOR_HPP_INCLUDED)
  7. #define BOOST_FUSION_SEGMENTED_ITERATOR_SEGMENTED_ITERATOR_HPP_INCLUDED
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/mpl/bool.hpp>
  10. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  11. #include <boost/fusion/iterator/iterator_facade.hpp>
  12. #include <boost/fusion/iterator/deref.hpp>
  13. #include <boost/fusion/iterator/deref_data.hpp>
  14. #include <boost/fusion/iterator/key_of.hpp>
  15. #include <boost/fusion/iterator/value_of.hpp>
  16. #include <boost/fusion/iterator/value_of_data.hpp>
  17. #include <boost/fusion/iterator/detail/segmented_equal_to.hpp>
  18. namespace boost { namespace fusion
  19. {
  20. struct nil_;
  21. namespace detail
  22. {
  23. template <typename Stack>
  24. struct segmented_next_impl;
  25. }
  26. // A segmented iterator wraps a "context", which is a cons list
  27. // of ranges, the frontmost is range over values and the rest
  28. // are ranges over internal segments.
  29. template <typename Context>
  30. struct segmented_iterator
  31. : iterator_facade<segmented_iterator<Context>, forward_traversal_tag>
  32. {
  33. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED explicit segmented_iterator(Context const& ctx)
  34. : context(ctx)
  35. {}
  36. //auto deref(it)
  37. //{
  38. // return deref(begin(car(it.context)))
  39. //}
  40. template <typename It>
  41. struct deref
  42. {
  43. typedef
  44. typename result_of::deref<
  45. typename It::context_type::car_type::begin_type
  46. >::type
  47. type;
  48. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  49. static type call(It const& it)
  50. {
  51. return *it.context.car.first;
  52. }
  53. };
  54. //auto deref_data(it)
  55. //{
  56. // return deref_data(begin(car(it.context)))
  57. //}
  58. template <typename It>
  59. struct deref_data
  60. {
  61. typedef
  62. typename result_of::deref_data<
  63. typename It::context_type::car_type::begin_type
  64. >::type
  65. type;
  66. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  67. static type call(It const& it)
  68. {
  69. return fusion::deref_data(it.context.car.first);
  70. }
  71. };
  72. //auto key_of(it)
  73. //{
  74. // return key_of(begin(car(it.context)))
  75. //}
  76. template <typename It>
  77. struct key_of
  78. : result_of::key_of<typename It::context_type::car_type::begin_type>
  79. {};
  80. //auto value_of(it)
  81. //{
  82. // return value_of(begin(car(it.context)))
  83. //}
  84. template <typename It>
  85. struct value_of
  86. : result_of::value_of<typename It::context_type::car_type::begin_type>
  87. {};
  88. //auto value_of_data(it)
  89. //{
  90. // return value_of_data(begin(car(it.context)))
  91. //}
  92. template <typename It>
  93. struct value_of_data
  94. : result_of::value_of_data<typename It::context_type::car_type::begin_type>
  95. {};
  96. // Compare all the segment iterators in each stack, starting with
  97. // the bottom-most.
  98. template <
  99. typename It1
  100. , typename It2
  101. , int Size1 = It1::context_type::size::value
  102. , int Size2 = It2::context_type::size::value
  103. >
  104. struct equal_to
  105. : mpl::false_
  106. {};
  107. template <typename It1, typename It2, int Size>
  108. struct equal_to<It1, It2, Size, Size>
  109. : detail::segmented_equal_to<
  110. typename It1::context_type
  111. , typename It2::context_type
  112. >
  113. {};
  114. template <typename It>
  115. struct next
  116. {
  117. typedef detail::segmented_next_impl<typename It::context_type> impl;
  118. typedef segmented_iterator<typename impl::type> type;
  119. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  120. static type call(It const& it)
  121. {
  122. return type(impl::call(it.context));
  123. }
  124. };
  125. typedef Context context_type;
  126. context_type context;
  127. };
  128. }}
  129. #endif