iterator.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef BOOST_MPL_AUX_RANGE_C_ITERATOR_HPP_INCLUDED
  2. #define BOOST_MPL_AUX_RANGE_C_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/iterator_tags.hpp>
  14. #include <boost/mpl/advance_fwd.hpp>
  15. #include <boost/mpl/distance_fwd.hpp>
  16. #include <boost/mpl/next_prior.hpp>
  17. #include <boost/mpl/deref.hpp>
  18. #include <boost/mpl/plus.hpp>
  19. #include <boost/mpl/minus.hpp>
  20. #include <boost/mpl/aux_/value_wknd.hpp>
  21. #include <boost/mpl/aux_/config/ctps.hpp>
  22. namespace boost { namespace mpl {
  23. // theoretically will work on any discrete numeric type
  24. template< typename N > struct r_iter
  25. {
  26. typedef aux::r_iter_tag tag;
  27. typedef random_access_iterator_tag category;
  28. typedef N type;
  29. #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  30. typedef r_iter< typename mpl::next<N>::type > next;
  31. typedef r_iter< typename mpl::prior<N>::type > prior;
  32. #endif
  33. };
  34. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  35. template<
  36. typename N
  37. >
  38. struct next< r_iter<N> >
  39. {
  40. typedef r_iter< typename mpl::next<N>::type > type;
  41. };
  42. template<
  43. typename N
  44. >
  45. struct prior< r_iter<N> >
  46. {
  47. typedef r_iter< typename mpl::prior<N>::type > type;
  48. };
  49. #endif
  50. template<> struct advance_impl<aux::r_iter_tag>
  51. {
  52. template< typename Iter, typename Dist > struct apply
  53. {
  54. typedef typename deref<Iter>::type n_;
  55. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  56. typedef typename plus_impl<integral_c_tag,integral_c_tag>
  57. ::template apply<n_,Dist>::type m_;
  58. #else
  59. typedef typename plus<n_,Dist>::type m_;
  60. #endif
  61. // agurt, 10/nov/04: to be generic, the code have to do something along
  62. // the lines below...
  63. //
  64. // typedef typename apply_wrap1<
  65. // numeric_cast< typename m_::tag, typename n_::tag >
  66. // , m_
  67. // >::type result_;
  68. //
  69. // ... meanwhile:
  70. typedef integral_c<
  71. typename aux::value_type_wknd<n_>::type
  72. , BOOST_MPL_AUX_VALUE_WKND(m_)::value
  73. > result_;
  74. typedef r_iter<result_> type;
  75. };
  76. };
  77. template<> struct distance_impl<aux::r_iter_tag>
  78. {
  79. template< typename Iter1, typename Iter2 > struct apply
  80. : minus<
  81. typename Iter2::type
  82. , typename Iter1::type
  83. >
  84. {
  85. };
  86. };
  87. }}
  88. #endif // BOOST_MPL_AUX_RANGE_C_ITERATOR_HPP_INCLUDED