iterator_adapter.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  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(FUSION_ITERATOR_ADAPTER_08112011_0942)
  7. #define FUSION_ITERATOR_ADAPTER_08112011_0942
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/support/category_of.hpp>
  10. #include <boost/fusion/iterator/advance.hpp>
  11. #include <boost/fusion/iterator/deref.hpp>
  12. #include <boost/fusion/iterator/distance.hpp>
  13. #include <boost/fusion/iterator/equal_to.hpp>
  14. #include <boost/fusion/iterator/iterator_facade.hpp>
  15. #include <boost/fusion/iterator/next.hpp>
  16. #include <boost/fusion/iterator/prior.hpp>
  17. #include <boost/fusion/iterator/value_of.hpp>
  18. #include <boost/type_traits/remove_const.hpp>
  19. #ifdef _MSC_VER
  20. # pragma warning(push)
  21. # pragma warning(disable: 4512) // assignment operator could not be generated.
  22. #endif
  23. namespace boost { namespace fusion
  24. {
  25. template <typename Derived_, typename Iterator_,
  26. typename Category = typename traits::category_of<Iterator_>::type>
  27. struct iterator_adapter
  28. : iterator_facade<Derived_, Category>
  29. {
  30. typedef typename
  31. remove_const<Iterator_>::type
  32. iterator_base_type;
  33. iterator_base_type iterator_base;
  34. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  35. iterator_adapter(iterator_base_type const& iterator_base_)
  36. : iterator_base(iterator_base_) {}
  37. // default implementation
  38. template <typename I1, typename I2>
  39. struct equal_to
  40. : result_of::equal_to<
  41. typename I1::iterator_base_type
  42. , typename I2::iterator_base_type
  43. >
  44. {};
  45. // default implementation
  46. template <typename Iterator, typename N>
  47. struct advance
  48. {
  49. typedef typename Derived_::template make<
  50. typename result_of::advance<
  51. typename Iterator::iterator_base_type, N
  52. >::type>::type
  53. type;
  54. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  55. static type
  56. call(Iterator const& it)
  57. {
  58. return type(fusion::advance<N>(it.iterator_base));
  59. }
  60. };
  61. // default implementation
  62. template <typename First, typename Last>
  63. struct distance
  64. : result_of::distance<
  65. typename First::iterator_base_type
  66. , typename Last::iterator_base_type
  67. >
  68. {};
  69. // default implementation
  70. template <typename Iterator>
  71. struct value_of
  72. : result_of::value_of<
  73. typename Iterator::iterator_base_type
  74. >
  75. {};
  76. // default implementation
  77. template <typename Iterator>
  78. struct deref
  79. {
  80. typedef typename
  81. result_of::deref<
  82. typename Iterator::iterator_base_type
  83. >::type
  84. type;
  85. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  86. static type
  87. call(Iterator const& it)
  88. {
  89. return fusion::deref(it.iterator_base);
  90. }
  91. };
  92. // default implementation
  93. template <typename Iterator>
  94. struct next
  95. {
  96. typedef typename Derived_::template make<
  97. typename result_of::next<
  98. typename Iterator::iterator_base_type
  99. >::type>::type
  100. type;
  101. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  102. static type
  103. call(Iterator const& i)
  104. {
  105. return type(fusion::next(i.iterator_base));
  106. }
  107. };
  108. // default implementation
  109. template <typename Iterator>
  110. struct prior
  111. {
  112. typedef typename Derived_::template make<
  113. typename result_of::prior<
  114. typename Iterator::iterator_base_type
  115. >::type>::type
  116. type;
  117. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  118. static type
  119. call(Iterator const& i)
  120. {
  121. return type(fusion::prior(i.iterator_base));
  122. }
  123. };
  124. };
  125. }}
  126. #ifdef _MSC_VER
  127. # pragma warning(pop)
  128. #endif
  129. #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
  130. namespace std
  131. {
  132. template <typename Derived, typename Iterator, typename Category>
  133. struct iterator_traits< ::boost::fusion::iterator_adapter<Derived, Iterator, Category> >
  134. { };
  135. }
  136. #endif
  137. #endif