]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/move/test/order_type.hpp
88c7eda9aa533b10b939ce48960c3071cabd96a4
[ceph.git] / ceph / src / boost / libs / move / test / order_type.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2015-2016.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // See http://www.boost.org/libs/move for documentation.
9 //
10 //////////////////////////////////////////////////////////////////////////////
11
12 #ifndef BOOST_MOVE_TEST_ORDER_TYPE_HPP
13 #define BOOST_MOVE_TEST_ORDER_TYPE_HPP
14
15 #include <boost/config.hpp>
16 #include <boost/move/core.hpp>
17 #include <boost/move/detail/iterator_traits.hpp>
18 #include <cstddef>
19 #include <cstdio>
20
21 struct order_perf_type
22 {
23 public:
24 std::size_t key;
25 std::size_t val;
26
27 order_perf_type()
28 : key(), val()
29 {
30 ++num_elements;
31 }
32
33 order_perf_type(const order_perf_type& other)
34 : key(other.key), val(other.val)
35 {
36 ++num_elements;
37 ++num_copy;
38 }
39
40 order_perf_type & operator=(const order_perf_type& other)
41 {
42 ++num_copy;
43 key = other.key;
44 val = other.val;
45 return *this;
46 }
47
48 ~order_perf_type ()
49 {
50 --num_elements;
51 }
52
53 static void reset_stats()
54 {
55 num_compare=0;
56 num_copy=0;
57 }
58
59 friend bool operator< (const order_perf_type& left, const order_perf_type& right)
60 { ++num_compare; return left.key < right.key; }
61
62 static boost::ulong_long_type num_compare;
63 static boost::ulong_long_type num_copy;
64 static boost::ulong_long_type num_elements;
65 };
66
67 boost::ulong_long_type order_perf_type::num_compare = 0;
68 boost::ulong_long_type order_perf_type::num_copy = 0;
69 boost::ulong_long_type order_perf_type::num_elements = 0;
70
71
72 struct order_move_type
73 {
74 BOOST_MOVABLE_BUT_NOT_COPYABLE(order_move_type)
75
76 public:
77 std::size_t key;
78 std::size_t val;
79
80 static const std::size_t moved_constr_mark = std::size_t(-1);
81 static const std::size_t moved_assign_mark = std::size_t(-2);
82
83 order_move_type()
84 : key(0u), val(0u)
85 {}
86
87 order_move_type(BOOST_RV_REF(order_move_type) other)
88 : key(other.key), val(other.val)
89 {
90 assert(this != &other);
91 other.key = other.val = std::size_t(-1);
92 }
93
94 order_move_type & operator=(BOOST_RV_REF(order_move_type) other)
95 {
96 assert(this != &other);
97 key = other.key;
98 val = other.val;
99 other.key = other.val = std::size_t(-2);
100 return *this;
101 }
102
103 friend bool operator< (const order_move_type& left, const order_move_type& right)
104 { return left.key < right.key; }
105
106 ~order_move_type ()
107 {
108 key = val = std::size_t(-3);
109 }
110 };
111
112 struct order_type_less
113 {
114 template<class T, class U>
115 bool operator()(const T &a, U const &b) const
116 { return a < b; }
117 };
118
119 template<class T>
120 inline bool is_order_type_ordered(T *elements, std::size_t element_count, bool stable = true)
121 {
122 for(std::size_t i = 1; i < element_count; ++i){
123 if(order_type_less()(elements[i], elements[i-1])){
124 std::printf("\n Ord KO !!!!");
125 return false;
126 }
127 if( stable && !(order_type_less()(elements[i-1], elements[i])) && (elements[i-1].val > elements[i].val) ){
128 std::printf("\n Stb KO !!!! ");
129 return false;
130 }
131 }
132 return true;
133 }
134
135 namespace boost {
136 namespace movelib {
137 namespace detail_adaptive {
138
139
140
141 }}}
142
143 template<class T>
144 inline bool is_key(T *elements, std::size_t element_count)
145 {
146 for(std::size_t i = 1; i < element_count; ++i){
147 if(elements[i].key >= element_count){
148 std::printf("\n Key.key KO !!!!");
149 return false;
150 }
151 if(elements[i].val != std::size_t(-1)){
152 std::printf("\n Key.val KO !!!!");
153 return false;
154 }
155 }
156 return true;
157 }
158
159 template<class T>
160 inline bool is_buffer(T *elements, std::size_t element_count)
161 {
162 for(std::size_t i = 1; i < element_count; ++i){
163 if(elements[i].key != std::size_t(-1)){
164 std::printf("\n Buf.key KO !!!!");
165 return false;
166 }
167 if(elements[i].val >= element_count){
168 std::printf("\n Buf.val KO !!!!");
169 return false;
170 }
171 }
172 return true;
173 }
174
175
176 //size_type iterator
177 template <class T, class D>
178 class randit
179 {
180 public:
181 typedef std::random_access_iterator_tag iterator_category;
182 typedef T value_type;
183 typedef D difference_type;
184 typedef T* pointer;
185 typedef T& reference;
186
187 private:
188 T* m_ptr;
189
190 public:
191 explicit randit(T* ptr)
192 : m_ptr(ptr)
193 {}
194
195 public:
196
197 //Constructors
198 randit()
199 : m_ptr() //Value initialization to achieve "null iterators" (N3644)
200 {}
201
202 randit(const randit& other)
203 : m_ptr(other.m_ptr)
204 {}
205
206 randit & operator=(const randit& other)
207 { m_ptr = other.m_ptr; return *this; }
208
209 //T* like operators
210 reference operator*() const
211 { return *m_ptr; }
212
213 pointer operator->() const
214 { return m_ptr; }
215
216 reference operator[](difference_type off) const
217 { return m_ptr[off]; }
218
219 //Increment / Decrement
220 randit& operator++()
221 { ++m_ptr; return *this; }
222
223 randit operator++(int)
224 { return randit(m_ptr++); }
225
226 randit& operator--()
227 { --m_ptr; return *this; }
228
229 randit operator--(int)
230 { return randit(m_ptr--); }
231
232 //Arithmetic
233 randit& operator+=(difference_type off)
234 { m_ptr += off; return *this; }
235
236 randit& operator-=(difference_type off)
237 { m_ptr -= off; return *this; }
238
239 friend randit operator+(const randit &x, difference_type off)
240 { return randit(x.m_ptr+off); }
241
242 friend randit operator+(difference_type off, randit right)
243 { right.m_ptr += off; return right; }
244
245 friend randit operator-(randit left, difference_type off)
246 { left.m_ptr -= off; return left; }
247
248 friend difference_type operator-(const randit &left, const randit& right)
249 { return difference_type(left.m_ptr - right.m_ptr); }
250
251 //Comparison operators
252 friend bool operator== (const randit& l, const randit& r)
253 { return l.m_ptr == r.m_ptr; }
254
255 friend bool operator!= (const randit& l, const randit& r)
256 { return l.m_ptr != r.m_ptr; }
257
258 friend bool operator< (const randit& l, const randit& r)
259 { return l.m_ptr < r.m_ptr; }
260
261 friend bool operator<= (const randit& l, const randit& r)
262 { return l.m_ptr <= r.m_ptr; }
263
264 friend bool operator> (const randit& l, const randit& r)
265 { return l.m_ptr > r.m_ptr; }
266
267 friend bool operator>= (const randit& l, const randit& r)
268 { return l.m_ptr >= r.m_ptr; }
269 };
270
271 struct less_int
272 {
273 bool operator()(int l, int r)
274 { return l < r; }
275 };
276
277
278 #endif //BOOST_MOVE_TEST_ORDER_TYPE_HPP