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