iterator.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef BOOST_MPL_AUX_VECTOR_ITERATOR_HPP_INCLUDED
  2. #define BOOST_MPL_AUX_VECTOR_ITERATOR_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/vector/aux_/at.hpp>
  14. #include <boost/mpl/iterator_tags.hpp>
  15. #include <boost/mpl/plus.hpp>
  16. #include <boost/mpl/minus.hpp>
  17. #include <boost/mpl/advance_fwd.hpp>
  18. #include <boost/mpl/distance_fwd.hpp>
  19. #include <boost/mpl/next.hpp>
  20. #include <boost/mpl/prior.hpp>
  21. #include <boost/mpl/aux_/nttp_decl.hpp>
  22. #include <boost/mpl/aux_/value_wknd.hpp>
  23. #include <boost/mpl/aux_/config/ctps.hpp>
  24. #include <boost/mpl/aux_/config/workaround.hpp>
  25. namespace boost { namespace mpl {
  26. template<
  27. typename Vector
  28. , BOOST_MPL_AUX_NTTP_DECL(long, n_)
  29. >
  30. struct v_iter
  31. {
  32. typedef aux::v_iter_tag tag;
  33. typedef random_access_iterator_tag category;
  34. typedef typename v_at<Vector,n_>::type type;
  35. typedef Vector vector_;
  36. typedef mpl::long_<n_> pos;
  37. #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  38. enum {
  39. next_ = n_ + 1
  40. , prior_ = n_ - 1
  41. , pos_ = n_
  42. };
  43. typedef v_iter<Vector,next_> next;
  44. typedef v_iter<Vector,prior_> prior;
  45. #endif
  46. };
  47. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  48. template<
  49. typename Vector
  50. , BOOST_MPL_AUX_NTTP_DECL(long, n_)
  51. >
  52. struct next< v_iter<Vector,n_> >
  53. {
  54. typedef v_iter<Vector,(n_ + 1)> type;
  55. };
  56. template<
  57. typename Vector
  58. , BOOST_MPL_AUX_NTTP_DECL(long, n_)
  59. >
  60. struct prior< v_iter<Vector,n_> >
  61. {
  62. typedef v_iter<Vector,(n_ - 1)> type;
  63. };
  64. template<
  65. typename Vector
  66. , BOOST_MPL_AUX_NTTP_DECL(long, n_)
  67. , typename Distance
  68. >
  69. struct advance< v_iter<Vector,n_>,Distance>
  70. {
  71. typedef v_iter<
  72. Vector
  73. , (n_ + BOOST_MPL_AUX_NESTED_VALUE_WKND(long, Distance))
  74. > type;
  75. };
  76. template<
  77. typename Vector
  78. , BOOST_MPL_AUX_NTTP_DECL(long, n_)
  79. , BOOST_MPL_AUX_NTTP_DECL(long, m_)
  80. >
  81. struct distance< v_iter<Vector,n_>, v_iter<Vector,m_> >
  82. : mpl::long_<(m_ - n_)>
  83. {
  84. };
  85. #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  86. template<> struct advance_impl<aux::v_iter_tag>
  87. {
  88. template< typename Iterator, typename N > struct apply
  89. {
  90. enum { pos_ = Iterator::pos_, n_ = N::value };
  91. typedef v_iter<
  92. typename Iterator::vector_
  93. , (pos_ + n_)
  94. > type;
  95. };
  96. };
  97. template<> struct distance_impl<aux::v_iter_tag>
  98. {
  99. template< typename Iter1, typename Iter2 > struct apply
  100. {
  101. enum { pos1_ = Iter1::pos_, pos2_ = Iter2::pos_ };
  102. typedef long_<( pos2_ - pos1_ )> type;
  103. BOOST_STATIC_CONSTANT(long, value = ( pos2_ - pos1_ ));
  104. };
  105. };
  106. #endif
  107. }}
  108. #endif // BOOST_MPL_AUX_VECTOR_ITERATOR_HPP_INCLUDED