mpl_iterator.hpp 3.0 KB

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