single_element_iter.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #ifndef BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED
  2. #define BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_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/int.hpp>
  19. #include <boost/mpl/aux_/nttp_decl.hpp>
  20. #include <boost/mpl/aux_/value_wknd.hpp>
  21. #include <boost/mpl/aux_/config/ctps.hpp>
  22. namespace boost { namespace mpl {
  23. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  24. namespace aux {
  25. template< typename T, BOOST_MPL_AUX_NTTP_DECL(int, is_last_) >
  26. struct sel_iter;
  27. template< typename T >
  28. struct sel_iter<T,0>
  29. {
  30. typedef random_access_iterator_tag category;
  31. typedef sel_iter<T,1> next;
  32. typedef T type;
  33. };
  34. template< typename T >
  35. struct sel_iter<T,1>
  36. {
  37. typedef random_access_iterator_tag category;
  38. typedef sel_iter<T,0> prior;
  39. };
  40. } // namespace aux
  41. template< typename T, BOOST_MPL_AUX_NTTP_DECL(int, is_last_), typename Distance >
  42. struct advance< aux::sel_iter<T,is_last_>,Distance>
  43. {
  44. typedef aux::sel_iter<
  45. T
  46. , ( is_last_ + BOOST_MPL_AUX_NESTED_VALUE_WKND(int, Distance) )
  47. > type;
  48. };
  49. template<
  50. typename T
  51. , BOOST_MPL_AUX_NTTP_DECL(int, l1)
  52. , BOOST_MPL_AUX_NTTP_DECL(int, l2)
  53. >
  54. struct distance< aux::sel_iter<T,l1>, aux::sel_iter<T,l2> >
  55. : int_<( l2 - l1 )>
  56. {
  57. };
  58. #else
  59. namespace aux {
  60. struct sel_iter_tag;
  61. template< typename T, BOOST_MPL_AUX_NTTP_DECL(int, is_last_) >
  62. struct sel_iter
  63. {
  64. enum { pos_ = is_last_ };
  65. typedef aux::sel_iter_tag tag;
  66. typedef random_access_iterator_tag category;
  67. typedef sel_iter<T,(is_last_ + 1)> next;
  68. typedef sel_iter<T,(is_last_ - 1)> prior;
  69. typedef T type;
  70. };
  71. } // namespace aux
  72. template<> struct advance_impl<aux::sel_iter_tag>
  73. {
  74. template< typename Iterator, typename N > struct apply
  75. {
  76. enum { pos_ = Iterator::pos_, n_ = N::value };
  77. typedef aux::sel_iter<
  78. typename Iterator::type
  79. , (pos_ + n_)
  80. > type;
  81. };
  82. };
  83. template<> struct distance_impl<aux::sel_iter_tag>
  84. {
  85. template< typename Iter1, typename Iter2 > struct apply
  86. {
  87. enum { pos1_ = Iter1::pos_, pos2_ = Iter2::pos_ };
  88. typedef int_<( pos2_ - pos1_ )> type;
  89. BOOST_STATIC_CONSTANT(int, value = ( pos2_ - pos1_ ));
  90. };
  91. };
  92. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  93. }}
  94. #endif // BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED