basic_iterator.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*=============================================================================
  2. Copyright (c) 2009 Christopher Schmidt
  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. #ifndef BOOST_FUSION_ITERATOR_BASIC_ITERATOR_HPP
  7. #define BOOST_FUSION_ITERATOR_BASIC_ITERATOR_HPP
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/iterator/iterator_facade.hpp>
  10. #include <boost/mpl/and.hpp>
  11. #include <boost/mpl/equal_to.hpp>
  12. #include <boost/mpl/minus.hpp>
  13. #include <boost/mpl/int.hpp>
  14. #include <boost/type_traits/is_same.hpp>
  15. #include <boost/type_traits/remove_const.hpp>
  16. namespace boost { namespace fusion
  17. {
  18. namespace extension
  19. {
  20. template <typename>
  21. struct value_of_impl;
  22. template <typename>
  23. struct deref_impl;
  24. template <typename>
  25. struct value_of_data_impl;
  26. template <typename>
  27. struct key_of_impl;
  28. template <typename>
  29. struct deref_data_impl;
  30. }
  31. template<typename Tag, typename Category, typename Seq, int Index>
  32. struct basic_iterator
  33. : iterator_facade<basic_iterator<Tag, Category, Seq, Index>, Category>
  34. {
  35. typedef mpl::int_<Index> index;
  36. typedef Seq seq_type;
  37. template <typename It>
  38. struct value_of
  39. : extension::value_of_impl<Tag>::template apply<It>
  40. {};
  41. template <typename It>
  42. struct deref
  43. : extension::deref_impl<Tag>::template apply<It>
  44. {};
  45. template <typename It>
  46. struct value_of_data
  47. : extension::value_of_data_impl<Tag>::template apply<It>
  48. {};
  49. template <typename It>
  50. struct key_of
  51. : extension::key_of_impl<Tag>::template apply<It>
  52. {};
  53. template <typename It>
  54. struct deref_data
  55. : extension::deref_data_impl<Tag>::template apply<It>
  56. {};
  57. template <typename It, typename N>
  58. struct advance
  59. {
  60. typedef
  61. basic_iterator<Tag, Category, Seq, Index + N::value>
  62. type;
  63. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  64. static type
  65. call(It const& it)
  66. {
  67. return type(*it.seq,0);
  68. }
  69. };
  70. template <typename It>
  71. struct next
  72. : advance<It, mpl::int_<1> >
  73. {};
  74. template <typename It>
  75. struct prior
  76. : advance<It, mpl::int_<-1> >
  77. {};
  78. template <typename It1, typename It2>
  79. struct distance
  80. {
  81. typedef mpl::minus<typename It2::index, typename It1::index> type;
  82. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  83. static
  84. type
  85. call(It1 const&, It2 const&)
  86. {
  87. return type();
  88. }
  89. };
  90. template <typename It1, typename It2>
  91. struct equal_to
  92. : mpl::and_<
  93. is_same<
  94. typename remove_const<typename It1::seq_type>::type
  95. , typename remove_const<typename It2::seq_type>::type
  96. >
  97. , mpl::equal_to<typename It1::index,typename It2::index>
  98. >
  99. {};
  100. template<typename OtherSeq>
  101. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  102. basic_iterator(basic_iterator<Tag,Category,OtherSeq,Index> const& it)
  103. : seq(it.seq)
  104. {}
  105. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  106. basic_iterator(Seq& in_seq, int)
  107. : seq(&in_seq)
  108. {}
  109. template<typename OtherSeq>
  110. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  111. basic_iterator&
  112. operator=(basic_iterator<Tag,Category,OtherSeq,Index> const& it)
  113. {
  114. seq=it.seq;
  115. return *this;
  116. }
  117. Seq* seq;
  118. };
  119. }}
  120. #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
  121. namespace std
  122. {
  123. template <typename Tag, typename Category, typename Seq, int Index>
  124. struct iterator_traits< ::boost::fusion::basic_iterator<Tag, Category, Seq, Index> >
  125. { };
  126. }
  127. #endif
  128. #endif