fix doc example typo
[boost.git] / boost / iterator / indirect_iterator.hpp
blobabff7e76346f12c4f9cc0cbe3c89f6a30b8d6f7d
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
10 #include <boost/iterator.hpp>
11 #include <boost/iterator/iterator_adaptor.hpp>
13 #include <boost/pointee.hpp>
14 #include <boost/indirect_reference.hpp>
15 #include <boost/detail/iterator.hpp>
17 #include <boost/detail/indirect_traits.hpp>
19 #include <boost/type_traits/is_same.hpp>
20 #include <boost/type_traits/add_reference.hpp>
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>
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
35 #include <boost/iterator/detail/config_def.hpp> // must be last #include
37 namespace boost
39 template <class Iter, class Value, class Category, class Reference, class Difference>
40 class indirect_iterator;
42 namespace detail
44 template <class Iter, class Value, class Category, class Reference, class Difference>
45 struct indirect_base
47 typedef typename iterator_traits<Iter>::value_type dereferenceable;
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>
63 >::type
64 , Difference
65 > type;
68 template <>
69 struct indirect_base<int, int, int, int, int> {};
70 } // namespace detail
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
80 class indirect_iterator
81 : public detail::indirect_base<
82 Iterator, Value, Category, Reference, Difference
83 >::type
85 typedef typename detail::indirect_base<
86 Iterator, Value, Category, Reference, Difference
87 >::type super_t;
89 friend class iterator_core_access;
91 public:
92 indirect_iterator() {}
94 indirect_iterator(Iterator iter)
95 : super_t(iter) {}
97 template <
98 class Iterator2, class Value2, class Category2
99 , class Reference2, class Difference2
101 indirect_iterator(
102 indirect_iterator<
103 Iterator2, Value2, Category2, Reference2, Difference2
104 > const& y
105 , typename enable_if_convertible<Iterator2, Iterator>::type* = 0
107 : super_t(y.base())
110 private:
111 typename super_t::reference dereference() const
113 # if BOOST_WORKAROUND(__BORLANDC__, < 0x5A0 )
114 return const_cast<super_t::reference>(**this->base());
115 # else
116 return **this->base();
117 # endif
121 template <class Iter>
122 inline
123 indirect_iterator<Iter> make_indirect_iterator(Iter x)
125 return indirect_iterator<Iter>(x);
128 template <class Traits, class Iter>
129 inline
130 indirect_iterator<Iter,Traits> make_indirect_iterator(Iter x, Traits* = 0)
132 return indirect_iterator<Iter, Traits>(x);
135 } // namespace boost
137 #include <boost/iterator/detail/config_undef.hpp>
139 #endif // BOOST_INDIRECT_ITERATOR_23022003THW_HPP