]> git.lyx.org Git - lyx.git/blob - boost/boost/iterator/indirect_iterator.hpp
Boost 1.31.0
[lyx.git] / boost / boost / iterator / indirect_iterator.hpp
1 // (C) Copyright David Abrahams 2002.
2 // (C) Copyright Jeremy Siek    2002.
3 // (C) Copyright Thomas Witt    2002.
4 // Permission to copy, use, modify,
5 // sell and distribute this software is granted provided this
6 // copyright notice appears in all copies. This software is provided
7 // "as is" without express or implied warranty, and with no claim as
8 // to its suitability for any purpose.
9 #ifndef BOOST_INDIRECT_ITERATOR_23022003THW_HPP
10 #define BOOST_INDIRECT_ITERATOR_23022003THW_HPP
11
12 #include <boost/iterator.hpp>
13 #include <boost/iterator/iterator_adaptor.hpp>
14
15 #include <boost/pointee.hpp>
16 #include <boost/indirect_reference.hpp>
17 #include <boost/detail/iterator.hpp>
18
19 #include <boost/python/detail/indirect_traits.hpp>
20
21 #include <boost/type_traits/is_same.hpp>
22 #include <boost/type_traits/add_reference.hpp>
23
24 #include <boost/mpl/bool.hpp>
25 #include <boost/mpl/identity.hpp>
26 #include <boost/mpl/apply_if.hpp>
27 #include <boost/mpl/not.hpp>
28 #include <boost/mpl/aux_/has_xxx.hpp>
29
30 #ifdef BOOST_MPL_NO_AUX_HAS_XXX
31 # include <boost/shared_ptr.hpp>
32 # include <boost/scoped_ptr.hpp>
33 # include <boost/mpl/bool.hpp>
34 # include <memory>
35 #endif 
36
37 #include <boost/iterator/detail/config_def.hpp> // must be last #include
38
39 namespace boost
40 {
41   template <class Iter, class Value, class Category, class Reference, class Difference>
42   class indirect_iterator;
43
44   namespace detail
45   {
46     template <class Iter, class Value, class Category, class Reference, class Difference>
47     struct indirect_base
48     {
49         typedef typename iterator_traits<Iter>::value_type dereferenceable;
50         
51         typedef iterator_adaptor<
52             indirect_iterator<Iter, Value, Category, Reference, Difference>
53           , Iter
54           , typename ia_dflt_help<
55                 Value, pointee<dereferenceable>
56             >::type
57           , Category
58           , typename ia_dflt_help<
59                 Reference
60               , mpl::apply_if<
61                     is_same<Value,use_default>
62                   , indirect_reference<dereferenceable>
63                   , add_reference<Value>
64                 >
65             >::type
66           , Difference
67         > type;
68     };
69
70     template <>
71     struct indirect_base<int, int, int, int, int> {};
72   } // namespace detail
73
74     
75   template <
76       class Iterator
77     , class Value = use_default
78     , class Category = use_default
79     , class Reference = use_default
80     , class Difference = use_default
81   >
82   class indirect_iterator
83     : public detail::indirect_base<
84         Iterator, Value, Category, Reference, Difference
85       >::type
86   {
87       typedef typename detail::indirect_base<
88           Iterator, Value, Category, Reference, Difference
89       >::type super_t;
90
91       friend class iterator_core_access;
92
93    public:
94       indirect_iterator() {}
95
96       indirect_iterator(Iterator iter)
97         : super_t(iter) {}
98
99       template <
100           class Iterator2, class Value2, class Category2
101         , class Reference2, class Difference2
102       >
103       indirect_iterator(
104           indirect_iterator<
105                Iterator2, Value2, Category2, Reference2, Difference2
106           > const& y
107         , typename enable_if_convertible<Iterator2, Iterator>::type* = 0
108       )
109         : super_t(y.base())
110       {}
111
112   private:    
113       typename super_t::reference dereference() const
114       {
115 # if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
116           return const_cast<super_t::reference>(**this->base());
117 # else
118           return **this->base();
119 # endif 
120       }
121   };
122
123   template <class Iter>
124   inline
125   indirect_iterator<Iter> make_indirect_iterator(Iter x)
126   {
127     return indirect_iterator<Iter>(x);
128   }
129
130   template <class Traits, class Iter>
131   inline
132   indirect_iterator<Iter,Traits> make_indirect_iterator(Iter x, Traits* = 0)
133   {
134     return indirect_iterator<Iter, Traits>(x);
135   }
136
137 } // namespace boost
138
139 #include <boost/iterator/detail/config_undef.hpp>
140
141 #endif // BOOST_INDIRECT_ITERATOR_23022003THW_HPP