mpl_iterator.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_MPL_ITERATOR_05052005_0731)
  7. #define FUSION_MPL_ITERATOR_05052005_0731
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/support/detail/mpl_iterator_category.hpp>
  10. #include <boost/fusion/iterator/iterator_facade.hpp>
  11. #include <boost/type_traits/remove_const.hpp>
  12. #include <boost/mpl/deref.hpp>
  13. #include <boost/mpl/next.hpp>
  14. #include <boost/mpl/prior.hpp>
  15. #include <boost/mpl/advance.hpp>
  16. #include <boost/mpl/distance.hpp>
  17. namespace boost { namespace fusion
  18. {
  19. template <typename Iterator_>
  20. struct mpl_iterator
  21. : iterator_facade<
  22. mpl_iterator<Iterator_>
  23. , typename detail::mpl_iterator_category<typename Iterator_::category>::type
  24. >
  25. {
  26. typedef typename remove_const<Iterator_>::type iterator_type;
  27. template <typename Iterator>
  28. struct value_of : mpl::deref<typename Iterator::iterator_type> {};
  29. template <typename Iterator>
  30. struct deref
  31. {
  32. typedef typename mpl::deref<
  33. typename Iterator::iterator_type>::type
  34. type;
  35. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  36. static type
  37. call(Iterator)
  38. {
  39. return type();
  40. }
  41. };
  42. template <typename Iterator>
  43. struct next
  44. {
  45. typedef mpl_iterator<
  46. typename mpl::next<typename Iterator::iterator_type>::type>
  47. type;
  48. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  49. static type
  50. call(Iterator)
  51. {
  52. return type();
  53. }
  54. };
  55. template <typename Iterator>
  56. struct prior
  57. {
  58. typedef mpl_iterator<
  59. typename mpl::prior<typename Iterator::iterator_type>::type>
  60. type;
  61. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  62. static type
  63. call(Iterator)
  64. {
  65. return type();
  66. }
  67. };
  68. template <typename Iterator, typename N>
  69. struct advance
  70. {
  71. typedef mpl_iterator<
  72. typename mpl::advance<typename Iterator::iterator_type, N>::type>
  73. type;
  74. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  75. static type
  76. call(Iterator const& /*i*/)
  77. {
  78. return type();
  79. }
  80. };
  81. template <typename I1, typename I2>
  82. struct distance :
  83. mpl::distance<
  84. typename I1::iterator_type
  85. , typename I2::iterator_type>
  86. {
  87. typedef typename
  88. mpl::distance<
  89. typename I1::iterator_type
  90. , typename I2::iterator_type
  91. >::type
  92. type;
  93. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  94. static type
  95. call(I1 const&, I2 const&)
  96. {
  97. return type();
  98. }
  99. };
  100. };
  101. }}
  102. #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
  103. namespace std
  104. {
  105. template <typename Iterator>
  106. struct iterator_traits< ::boost::fusion::mpl_iterator<Iterator> >
  107. { };
  108. }
  109. #endif
  110. #endif