[3428] | 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 | |
---|
| 10 | #include <boost/iterator.hpp> |
---|
| 11 | #include <boost/iterator/iterator_adaptor.hpp> |
---|
| 12 | |
---|
| 13 | #include <boost/pointee.hpp> |
---|
| 14 | #include <boost/indirect_reference.hpp> |
---|
| 15 | #include <boost/detail/iterator.hpp> |
---|
| 16 | |
---|
| 17 | #include <boost/detail/indirect_traits.hpp> |
---|
| 18 | |
---|
| 19 | #include <boost/type_traits/is_same.hpp> |
---|
| 20 | #include <boost/type_traits/add_reference.hpp> |
---|
| 21 | |
---|
| 22 | #include <boost/mpl/bool.hpp> |
---|
| 23 | #include <boost/mpl/identity.hpp> |
---|
| 24 | #include <boost/mpl/eval_if.hpp> |
---|
| 25 | #include <boost/mpl/not.hpp> |
---|
| 26 | #include <boost/mpl/has_xxx.hpp> |
---|
| 27 | |
---|
| 28 | #ifdef BOOST_MPL_CFG_NO_HAS_XXX |
---|
| 29 | # include <boost/shared_ptr.hpp> |
---|
| 30 | # include <boost/scoped_ptr.hpp> |
---|
| 31 | # include <boost/mpl/bool.hpp> |
---|
| 32 | # include <memory> |
---|
| 33 | #endif |
---|
| 34 | |
---|
| 35 | #include <boost/iterator/detail/config_def.hpp> // must be last #include |
---|
| 36 | |
---|
| 37 | namespace boost |
---|
| 38 | { |
---|
| 39 | template <class Iter, class Value, class Category, class Reference, class Difference> |
---|
| 40 | class indirect_iterator; |
---|
| 41 | |
---|
| 42 | namespace detail |
---|
| 43 | { |
---|
| 44 | template <class Iter, class Value, class Category, class Reference, class Difference> |
---|
| 45 | struct indirect_base |
---|
| 46 | { |
---|
| 47 | typedef typename iterator_traits<Iter>::value_type dereferenceable; |
---|
| 48 | |
---|
| 49 | typedef iterator_adaptor< |
---|
| 50 | indirect_iterator<Iter, Value, Category, Reference, Difference> |
---|
| 51 | , Iter |
---|
| 52 | , typename ia_dflt_help< |
---|
| 53 | Value, pointee<dereferenceable> |
---|
| 54 | >::type |
---|
| 55 | , Category |
---|
| 56 | , typename ia_dflt_help< |
---|
| 57 | Reference |
---|
| 58 | , mpl::eval_if< |
---|
| 59 | is_same<Value,use_default> |
---|
| 60 | , indirect_reference<dereferenceable> |
---|
| 61 | , add_reference<Value> |
---|
| 62 | > |
---|
| 63 | >::type |
---|
| 64 | , Difference |
---|
| 65 | > type; |
---|
| 66 | }; |
---|
| 67 | |
---|
| 68 | template <> |
---|
| 69 | struct indirect_base<int, int, int, int, int> {}; |
---|
| 70 | } // namespace detail |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | template < |
---|
| 74 | class Iterator |
---|
| 75 | , class Value = use_default |
---|
| 76 | , class Category = use_default |
---|
| 77 | , class Reference = use_default |
---|
| 78 | , class Difference = use_default |
---|
| 79 | > |
---|
| 80 | class indirect_iterator |
---|
| 81 | : public detail::indirect_base< |
---|
| 82 | Iterator, Value, Category, Reference, Difference |
---|
| 83 | >::type |
---|
| 84 | { |
---|
| 85 | typedef typename detail::indirect_base< |
---|
| 86 | Iterator, Value, Category, Reference, Difference |
---|
| 87 | >::type super_t; |
---|
| 88 | |
---|
| 89 | friend class iterator_core_access; |
---|
| 90 | |
---|
| 91 | public: |
---|
| 92 | indirect_iterator() {} |
---|
| 93 | |
---|
| 94 | indirect_iterator(Iterator iter) |
---|
| 95 | : super_t(iter) {} |
---|
| 96 | |
---|
| 97 | template < |
---|
| 98 | class Iterator2, class Value2, class Category2 |
---|
| 99 | , class Reference2, class Difference2 |
---|
| 100 | > |
---|
| 101 | indirect_iterator( |
---|
| 102 | indirect_iterator< |
---|
| 103 | Iterator2, Value2, Category2, Reference2, Difference2 |
---|
| 104 | > const& y |
---|
| 105 | , typename enable_if_convertible<Iterator2, Iterator>::type* = 0 |
---|
| 106 | ) |
---|
| 107 | : super_t(y.base()) |
---|
| 108 | {} |
---|
| 109 | |
---|
| 110 | private: |
---|
| 111 | typename super_t::reference dereference() const |
---|
| 112 | { |
---|
| 113 | # if BOOST_WORKAROUND(__BORLANDC__, < 0x5A0 ) |
---|
| 114 | return const_cast<super_t::reference>(**this->base()); |
---|
| 115 | # else |
---|
| 116 | return **this->base(); |
---|
| 117 | # endif |
---|
| 118 | } |
---|
| 119 | }; |
---|
| 120 | |
---|
| 121 | template <class Iter> |
---|
| 122 | inline |
---|
| 123 | indirect_iterator<Iter> make_indirect_iterator(Iter x) |
---|
| 124 | { |
---|
| 125 | return indirect_iterator<Iter>(x); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | template <class Traits, class Iter> |
---|
| 129 | inline |
---|
| 130 | indirect_iterator<Iter,Traits> make_indirect_iterator(Iter x, Traits* = 0) |
---|
| 131 | { |
---|
| 132 | return indirect_iterator<Iter, Traits>(x); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | } // namespace boost |
---|
| 136 | |
---|
| 137 | #include <boost/iterator/detail/config_undef.hpp> |
---|
| 138 | |
---|
| 139 | #endif // BOOST_INDIRECT_ITERATOR_23022003THW_HPP |
---|