indirect_iterator.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // (C) Copyright David Abrahams 2002.
  2. // (C) Copyright Jeremy Siek 2002.
  3. // (C) Copyright Thomas Witt 2002.
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_INDIRECT_ITERATOR_23022003THW_HPP
  8. #define BOOST_INDIRECT_ITERATOR_23022003THW_HPP
  9. #include <boost/iterator/iterator_adaptor.hpp>
  10. #include <boost/pointee.hpp>
  11. #include <boost/indirect_reference.hpp>
  12. #include <boost/detail/indirect_traits.hpp>
  13. #include <boost/type_traits/is_same.hpp>
  14. #include <boost/type_traits/add_reference.hpp>
  15. #include <boost/mpl/bool.hpp>
  16. #include <boost/mpl/identity.hpp>
  17. #include <boost/mpl/eval_if.hpp>
  18. #include <boost/mpl/not.hpp>
  19. #include <boost/mpl/has_xxx.hpp>
  20. #include <iterator>
  21. #ifdef BOOST_MPL_CFG_NO_HAS_XXX
  22. # include <boost/shared_ptr.hpp>
  23. # include <boost/scoped_ptr.hpp>
  24. # include <boost/mpl/bool.hpp>
  25. # include <memory>
  26. #endif
  27. #include <boost/iterator/detail/config_def.hpp> // must be last #include
  28. namespace boost {
  29. namespace iterators {
  30. template <class Iter, class Value, class Category, class Reference, class Difference>
  31. class indirect_iterator;
  32. namespace detail
  33. {
  34. template <class Iter, class Value, class Category, class Reference, class Difference>
  35. struct indirect_base
  36. {
  37. typedef typename std::iterator_traits<Iter>::value_type dereferenceable;
  38. typedef iterator_adaptor<
  39. indirect_iterator<Iter, Value, Category, Reference, Difference>
  40. , Iter
  41. , typename ia_dflt_help<
  42. Value, pointee<dereferenceable>
  43. >::type
  44. , Category
  45. , typename ia_dflt_help<
  46. Reference
  47. , mpl::eval_if<
  48. is_same<Value,use_default>
  49. , indirect_reference<dereferenceable>
  50. , add_reference<Value>
  51. >
  52. >::type
  53. , Difference
  54. > type;
  55. };
  56. template <>
  57. struct indirect_base<int, int, int, int, int> {};
  58. } // namespace detail
  59. template <
  60. class Iterator
  61. , class Value = use_default
  62. , class Category = use_default
  63. , class Reference = use_default
  64. , class Difference = use_default
  65. >
  66. class indirect_iterator
  67. : public detail::indirect_base<
  68. Iterator, Value, Category, Reference, Difference
  69. >::type
  70. {
  71. typedef typename detail::indirect_base<
  72. Iterator, Value, Category, Reference, Difference
  73. >::type super_t;
  74. friend class iterator_core_access;
  75. public:
  76. indirect_iterator() {}
  77. indirect_iterator(Iterator iter)
  78. : super_t(iter) {}
  79. template <
  80. class Iterator2, class Value2, class Category2
  81. , class Reference2, class Difference2
  82. >
  83. indirect_iterator(
  84. indirect_iterator<
  85. Iterator2, Value2, Category2, Reference2, Difference2
  86. > const& y
  87. , typename enable_if_convertible<Iterator2, Iterator>::type* = 0
  88. )
  89. : super_t(y.base())
  90. {}
  91. private:
  92. typename super_t::reference dereference() const
  93. {
  94. # if BOOST_WORKAROUND(__BORLANDC__, < 0x5A0 )
  95. return const_cast<super_t::reference>(**this->base());
  96. # else
  97. return **this->base();
  98. # endif
  99. }
  100. };
  101. template <class Iter>
  102. inline
  103. indirect_iterator<Iter> make_indirect_iterator(Iter x)
  104. {
  105. return indirect_iterator<Iter>(x);
  106. }
  107. template <class Traits, class Iter>
  108. inline
  109. indirect_iterator<Iter,Traits> make_indirect_iterator(Iter x, Traits* = 0)
  110. {
  111. return indirect_iterator<Iter, Traits>(x);
  112. }
  113. } // namespace iterators
  114. using iterators::indirect_iterator;
  115. using iterators::make_indirect_iterator;
  116. } // namespace boost
  117. #include <boost/iterator/detail/config_undef.hpp>
  118. #endif // BOOST_INDIRECT_ITERATOR_23022003THW_HPP