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