]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/interprocess/detail/transform_iterator.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / interprocess / detail / transform_iterator.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-2015.
4 // (C) Copyright Gennaro Prota 2003 - 2004.
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10 // See http://www.boost.org/libs/interprocess for documentation.
11 //
12 //////////////////////////////////////////////////////////////////////////////
13
14 #ifndef BOOST_INTERPROCESS_DETAIL_TRANSFORM_ITERATORS_HPP
15 #define BOOST_INTERPROCESS_DETAIL_TRANSFORM_ITERATORS_HPP
16
17 #ifndef BOOST_CONFIG_HPP
18 # include <boost/config.hpp>
19 #endif
20 #
21 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 # pragma once
23 #endif
24
25 #include <boost/interprocess/detail/config_begin.hpp>
26 #include <boost/interprocess/detail/workaround.hpp>
27
28 // interprocess
29 #include <boost/interprocess/interprocess_fwd.hpp>
30 // interprocess/detail
31 #include <boost/interprocess/detail/type_traits.hpp>
32 // move/detail
33 #include <boost/container/detail/iterator.hpp>
34
35 namespace boost {
36 namespace interprocess {
37
38 template <class PseudoReference>
39 struct operator_arrow_proxy
40 {
41 operator_arrow_proxy(const PseudoReference &px)
42 : m_value(px)
43 {}
44
45 PseudoReference* operator->() const { return &m_value; }
46 // This function is needed for MWCW and BCC, which won't call operator->
47 // again automatically per 13.3.1.2 para 8
48 // operator T*() const { return &m_value; }
49 mutable PseudoReference m_value;
50 };
51
52 template <class T>
53 struct operator_arrow_proxy<T&>
54 {
55 operator_arrow_proxy(T &px)
56 : m_value(px)
57 {}
58
59 T* operator->() const { return const_cast<T*>(&m_value); }
60 // This function is needed for MWCW and BCC, which won't call operator->
61 // again automatically per 13.3.1.2 para 8
62 // operator T*() const { return &m_value; }
63 T &m_value;
64 };
65
66 template <class Iterator, class UnaryFunction>
67 class transform_iterator
68 : public UnaryFunction
69 {
70 public:
71 typedef typename ::boost::container::iterator_traits<Iterator>::iterator_category iterator_category;
72 typedef typename ipcdetail::remove_reference<typename UnaryFunction::result_type>::type value_type;
73 typedef typename ::boost::container::iterator_traits<Iterator>::difference_type difference_type;
74 typedef operator_arrow_proxy<typename UnaryFunction::result_type> pointer;
75 typedef typename UnaryFunction::result_type reference;
76
77 explicit transform_iterator(const Iterator &it, const UnaryFunction &f = UnaryFunction())
78 : UnaryFunction(f), m_it(it)
79 {}
80
81 explicit transform_iterator()
82 : UnaryFunction(), m_it()
83 {}
84
85 //Constructors
86 transform_iterator& operator++()
87 { increment(); return *this; }
88
89 transform_iterator operator++(int)
90 {
91 transform_iterator result (*this);
92 increment();
93 return result;
94 }
95
96 transform_iterator& operator--()
97 { decrement(); return *this; }
98
99 transform_iterator operator--(int)
100 {
101 transform_iterator result (*this);
102 decrement();
103 return result;
104 }
105
106 friend bool operator== (const transform_iterator& i, const transform_iterator& i2)
107 { return i.equal(i2); }
108
109 friend bool operator!= (const transform_iterator& i, const transform_iterator& i2)
110 { return !(i == i2); }
111
112 friend bool operator< (const transform_iterator& i, const transform_iterator& i2)
113 { return i < i2; }
114
115 friend bool operator> (const transform_iterator& i, const transform_iterator& i2)
116 { return i2 < i; }
117
118 friend bool operator<= (const transform_iterator& i, const transform_iterator& i2)
119 { return !(i > i2); }
120
121 friend bool operator>= (const transform_iterator& i, const transform_iterator& i2)
122 { return !(i < i2); }
123
124 friend difference_type operator- (const transform_iterator& i, const transform_iterator& i2)
125 { return i2.distance_to(i); }
126
127 //Arithmetic
128 transform_iterator& operator+=(difference_type off)
129 { this->advance(off); return *this; }
130
131 transform_iterator operator+(difference_type off) const
132 {
133 transform_iterator other(*this);
134 other.advance(off);
135 return other;
136 }
137
138 friend transform_iterator operator+(difference_type off, const transform_iterator& right)
139 { return right + off; }
140
141 transform_iterator& operator-=(difference_type off)
142 { this->advance(-off); return *this; }
143
144 transform_iterator operator-(difference_type off) const
145 { return *this + (-off); }
146
147 typename UnaryFunction::result_type operator*() const
148 { return dereference(); }
149
150 typename UnaryFunction::result_type operator[](difference_type off) const
151 { return UnaryFunction::operator()(m_it[off]); }
152
153 operator_arrow_proxy<typename UnaryFunction::result_type>
154 operator->() const
155 { return operator_arrow_proxy<typename UnaryFunction::result_type>(dereference()); }
156
157 Iterator & base()
158 { return m_it; }
159
160 const Iterator & base() const
161 { return m_it; }
162
163 private:
164 Iterator m_it;
165
166 void increment()
167 { ++m_it; }
168
169 void decrement()
170 { --m_it; }
171
172 bool equal(const transform_iterator &other) const
173 { return m_it == other.m_it; }
174
175 bool less(const transform_iterator &other) const
176 { return other.m_it < m_it; }
177
178 typename UnaryFunction::result_type dereference() const
179 { return UnaryFunction::operator()(*m_it); }
180
181 void advance(difference_type n)
182 { ::boost::container::iterator_advance(m_it, n); }
183
184 difference_type distance_to(const transform_iterator &other)const
185 { return ::boost::container::iterator_distance(other.m_it, m_it); }
186 };
187
188 template <class Iterator, class UnaryFunc>
189 transform_iterator<Iterator, UnaryFunc>
190 make_transform_iterator(Iterator it, UnaryFunc fun)
191 {
192 return transform_iterator<Iterator, UnaryFunc>(it, fun);
193 }
194
195 } //namespace interprocess {
196 } //namespace boost {
197
198 #include <boost/interprocess/detail/config_end.hpp>
199
200 #endif //#ifndef BOOST_INTERPROCESS_DETAIL_TRANSFORM_ITERATORS_HPP