iterator_adapter.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. namespace boost { namespace fusion
  20. {
  21. template <typename Derived_, typename Iterator_,
  22. typename Category = typename traits::category_of<Iterator_>::type>
  23. struct iterator_adapter
  24. : iterator_facade<Derived_, Category>
  25. {
  26. typedef typename
  27. remove_const<Iterator_>::type
  28. iterator_base_type;
  29. iterator_base_type iterator_base;
  30. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  31. iterator_adapter(iterator_base_type const& iterator_base_)
  32. : iterator_base(iterator_base_) {}
  33. // default implementation
  34. template <typename I1, typename I2>
  35. struct equal_to
  36. : result_of::equal_to<
  37. typename I1::iterator_base_type
  38. , typename I2::iterator_base_type
  39. >
  40. {};
  41. // default implementation
  42. template <typename Iterator, typename N>
  43. struct advance
  44. {
  45. typedef typename Derived_::template make<
  46. typename result_of::advance<
  47. typename Iterator::iterator_base_type, N
  48. >::type>::type
  49. type;
  50. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  51. static type
  52. call(Iterator const& it)
  53. {
  54. return type(fusion::advance<N>(it.iterator_base));
  55. }
  56. };
  57. // default implementation
  58. template <typename First, typename Last>
  59. struct distance
  60. : result_of::distance<
  61. typename First::iterator_base_type
  62. , typename Last::iterator_base_type
  63. >
  64. {};
  65. // default implementation
  66. template <typename Iterator>
  67. struct value_of
  68. : result_of::value_of<
  69. typename Iterator::iterator_base_type
  70. >
  71. {};
  72. // default implementation
  73. template <typename Iterator>
  74. struct deref
  75. {
  76. typedef typename
  77. result_of::deref<
  78. typename Iterator::iterator_base_type
  79. >::type
  80. type;
  81. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  82. static type
  83. call(Iterator const& it)
  84. {
  85. return fusion::deref(it.iterator_base);
  86. }
  87. };
  88. // default implementation
  89. template <typename Iterator>
  90. struct next
  91. {
  92. typedef typename Derived_::template make<
  93. typename result_of::next<
  94. typename Iterator::iterator_base_type
  95. >::type>::type
  96. type;
  97. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  98. static type
  99. call(Iterator const& i)
  100. {
  101. return type(fusion::next(i.iterator_base));
  102. }
  103. };
  104. // default implementation
  105. template <typename Iterator>
  106. struct prior
  107. {
  108. typedef typename Derived_::template make<
  109. typename result_of::prior<
  110. typename Iterator::iterator_base_type
  111. >::type>::type
  112. type;
  113. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  114. static type
  115. call(Iterator const& i)
  116. {
  117. return type(fusion::prior(i.iterator_base));
  118. }
  119. };
  120. };
  121. }}
  122. #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
  123. namespace std
  124. {
  125. template <typename Derived, typename Iterator, typename Category>
  126. struct iterator_traits< ::boost::fusion::iterator_adapter<Derived, Iterator, Category> >
  127. { };
  128. }
  129. #endif
  130. #endif