]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/container/test/movable_int.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / container / test / movable_int.hpp
CommitLineData
7c673cae
FG
1///////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost
4// Software License, Version 1.0. (See accompanying file
5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// See http://www.boost.org/libs/container for documentation.
8//
9///////////////////////////////////////////////////////////////////////////
10
11#ifndef BOOST_CONTAINER_TEST_MOVABLE_INT_HEADER
12#define BOOST_CONTAINER_TEST_MOVABLE_INT_HEADER
13
14#include <boost/container/detail/config_begin.hpp>
15#include <boost/container/detail/workaround.hpp>
16#include <boost/move/utility_core.hpp>
17#include <ostream>
18#include <climits>
19#include <boost/assert.hpp>
20
21namespace boost {
22namespace container {
23namespace test {
24
25template<class T>
26struct is_copyable;
27
28template<>
29struct is_copyable<int>
30{
31 static const bool value = true;
32};
33
34
35class movable_int
36{
37 BOOST_MOVABLE_BUT_NOT_COPYABLE(movable_int)
38
39 public:
40
41 static unsigned int count;
42
43 movable_int()
44 : m_int(0)
45 { ++count; }
46
47 explicit movable_int(int a)
48 : m_int(a)
49 {
50 //Disallow INT_MIN
51 BOOST_ASSERT(this->m_int != INT_MIN);
52 ++count;
53 }
54
55 movable_int(BOOST_RV_REF(movable_int) mmi)
56 : m_int(mmi.m_int)
57 { mmi.m_int = 0; ++count; }
58
59 movable_int & operator= (BOOST_RV_REF(movable_int) mmi)
60 { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; }
61
62 movable_int & operator= (int i)
63 { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
64
65 ~movable_int()
66 {
67 //Double destructor called
68 BOOST_ASSERT(this->m_int != INT_MIN);
69 this->m_int = INT_MIN;
70 --count;
71 }
72
73 friend bool operator ==(const movable_int &l, const movable_int &r)
74 { return l.m_int == r.m_int; }
75
76 friend bool operator !=(const movable_int &l, const movable_int &r)
77 { return l.m_int != r.m_int; }
78
79 friend bool operator <(const movable_int &l, const movable_int &r)
80 { return l.m_int < r.m_int; }
81
82 friend bool operator <=(const movable_int &l, const movable_int &r)
83 { return l.m_int <= r.m_int; }
84
85 friend bool operator >=(const movable_int &l, const movable_int &r)
86 { return l.m_int >= r.m_int; }
87
88 friend bool operator >(const movable_int &l, const movable_int &r)
89 { return l.m_int > r.m_int; }
90
91 int get_int() const
92 { return m_int; }
93
94 friend bool operator==(const movable_int &l, int r)
95 { return l.get_int() == r; }
96
97 friend bool operator==(int l, const movable_int &r)
98 { return l == r.get_int(); }
99
92f5a8d4
TL
100 friend bool operator<(const movable_int &l, int r)
101 { return l.get_int() < r; }
102
103 friend bool operator<(int l, const movable_int &r)
104 { return l < r.get_int(); }
105
106 friend std::size_t hash_value(const movable_int &v)
107 { return (std::size_t)v.get_int(); }
108
7c673cae
FG
109 private:
110 int m_int;
111};
112
113unsigned int movable_int::count = 0;
114
115inline movable_int produce_movable_int()
116{ return movable_int(); }
117
118template<class E, class T>
119std::basic_ostream<E, T> & operator<<
120 (std::basic_ostream<E, T> & os, movable_int const & p)
121
122{
123 os << p.get_int();
124 return os;
125}
126
127template<>
128struct is_copyable<movable_int>
129{
130 static const bool value = false;
131};
132
133class movable_and_copyable_int
134{
135 BOOST_COPYABLE_AND_MOVABLE(movable_and_copyable_int)
136
137 public:
138
139 static unsigned int count;
140
141 movable_and_copyable_int()
142 : m_int(0)
143 { ++count; }
144
145 explicit movable_and_copyable_int(int a)
146 : m_int(a)
147 {
148 //Disallow INT_MIN
149 BOOST_ASSERT(this->m_int != INT_MIN);
150 ++count;
151 }
152
153 movable_and_copyable_int(const movable_and_copyable_int& mmi)
154 : m_int(mmi.m_int)
155 { ++count; }
156
157 movable_and_copyable_int(BOOST_RV_REF(movable_and_copyable_int) mmi)
158 : m_int(mmi.m_int)
159 { mmi.m_int = 0; ++count; }
160
161 ~movable_and_copyable_int()
162 {
163 //Double destructor called
164 BOOST_ASSERT(this->m_int != INT_MIN);
165 this->m_int = INT_MIN;
166 --count;
167 }
168
169 movable_and_copyable_int &operator= (BOOST_COPY_ASSIGN_REF(movable_and_copyable_int) mi)
170 { this->m_int = mi.m_int; return *this; }
171
172 movable_and_copyable_int & operator= (BOOST_RV_REF(movable_and_copyable_int) mmi)
173 { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; }
174
175 movable_and_copyable_int & operator= (int i)
176 { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
177
178 friend bool operator ==(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
179 { return l.m_int == r.m_int; }
180
181 friend bool operator !=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
182 { return l.m_int != r.m_int; }
183
184 friend bool operator <(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
185 { return l.m_int < r.m_int; }
186
187 friend bool operator <=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
188 { return l.m_int <= r.m_int; }
189
190 friend bool operator >=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
191 { return l.m_int >= r.m_int; }
192
193 friend bool operator >(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
194 { return l.m_int > r.m_int; }
195
196 int get_int() const
197 { return m_int; }
198
199 friend bool operator==(const movable_and_copyable_int &l, int r)
200 { return l.get_int() == r; }
201
202 friend bool operator==(int l, const movable_and_copyable_int &r)
203 { return l == r.get_int(); }
204
92f5a8d4
TL
205 friend bool operator<(const movable_and_copyable_int &l, int r)
206 { return l.get_int() < r; }
207
208 friend bool operator<(int l, const movable_and_copyable_int &r)
209 { return l < r.get_int(); }
210
211 friend std::size_t hash_value(const movable_and_copyable_int &v)
212 { return (std::size_t)v.get_int(); }
213
7c673cae
FG
214 private:
215 int m_int;
216};
217
218unsigned int movable_and_copyable_int::count = 0;
219
220inline movable_and_copyable_int produce_movable_and_copyable_int()
221{ return movable_and_copyable_int(); }
222
223template<class E, class T>
224std::basic_ostream<E, T> & operator<<
225 (std::basic_ostream<E, T> & os, movable_and_copyable_int const & p)
226
227{
228 os << p.get_int();
229 return os;
230}
231
232template<>
233struct is_copyable<movable_and_copyable_int>
234{
235 static const bool value = true;
236};
237
238class copyable_int
239{
240 public:
241
242 static unsigned int count;
243
244 copyable_int()
245 : m_int(0)
246 { ++count; }
247
248 explicit copyable_int(int a)
249 : m_int(a)
250 {
251 //Disallow INT_MIN
252 BOOST_ASSERT(this->m_int != INT_MIN);
253 ++count;
254 }
255
256 copyable_int(const copyable_int& mmi)
257 : m_int(mmi.m_int)
258 { ++count; }
259
260 copyable_int & operator= (int i)
261 { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
262
263 copyable_int & operator= (const copyable_int &ci)
264 { this->m_int = ci.m_int; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
265
266 ~copyable_int()
267 {
268 //Double destructor called
269 BOOST_ASSERT(this->m_int != INT_MIN);
270 this->m_int = INT_MIN;
271 --count;
272 }
273
274 friend bool operator ==(const copyable_int &l, const copyable_int &r)
275 { return l.m_int == r.m_int; }
276
277 friend bool operator !=(const copyable_int &l, const copyable_int &r)
278 { return l.m_int != r.m_int; }
279
280 friend bool operator <(const copyable_int &l, const copyable_int &r)
281 { return l.m_int < r.m_int; }
282
283 friend bool operator <=(const copyable_int &l, const copyable_int &r)
284 { return l.m_int <= r.m_int; }
285
286 friend bool operator >=(const copyable_int &l, const copyable_int &r)
287 { return l.m_int >= r.m_int; }
288
289 friend bool operator >(const copyable_int &l, const copyable_int &r)
290 { return l.m_int > r.m_int; }
291
292 int get_int() const
293 { return m_int; }
294
295 friend bool operator==(const copyable_int &l, int r)
296 { return l.get_int() == r; }
297
298 friend bool operator==(int l, const copyable_int &r)
299 { return l == r.get_int(); }
300
92f5a8d4
TL
301 friend bool operator<(const copyable_int &l, int r)
302 { return l.get_int() < r; }
303
304 friend bool operator<(int l, const copyable_int &r)
305 { return l < r.get_int(); }
306
307 friend std::size_t hash_value(const copyable_int &v)
308 { return (std::size_t)v.get_int(); }
309
7c673cae
FG
310 private:
311 int m_int;
312};
313
314unsigned int copyable_int::count = 0;
315
316inline copyable_int produce_copyable_int()
317{ return copyable_int(); }
318
319template<class E, class T>
320std::basic_ostream<E, T> & operator<<
321 (std::basic_ostream<E, T> & os, copyable_int const & p)
322
323{
324 os << p.get_int();
325 return os;
326}
327
328template<>
329struct is_copyable<copyable_int>
330{
331 static const bool value = true;
332};
333
334class non_copymovable_int
335{
336 non_copymovable_int(const non_copymovable_int& mmi);
337 non_copymovable_int & operator= (const non_copymovable_int &mi);
338
339 public:
340
341 static unsigned int count;
342
343 non_copymovable_int()
344 : m_int(0)
345 { ++count; }
346
347 explicit non_copymovable_int(int a)
348 : m_int(a)
349 { ++count; }
350
351 ~non_copymovable_int()
352 { m_int = 0; --count; }
353
354 bool operator ==(const non_copymovable_int &mi) const
355 { return this->m_int == mi.m_int; }
356
357 bool operator !=(const non_copymovable_int &mi) const
358 { return this->m_int != mi.m_int; }
359
360 bool operator <(const non_copymovable_int &mi) const
361 { return this->m_int < mi.m_int; }
362
363 bool operator <=(const non_copymovable_int &mi) const
364 { return this->m_int <= mi.m_int; }
365
366 bool operator >=(const non_copymovable_int &mi) const
367 { return this->m_int >= mi.m_int; }
368
369 bool operator >(const non_copymovable_int &mi) const
370 { return this->m_int > mi.m_int; }
371
372 int get_int() const
373 { return m_int; }
374
375 friend bool operator==(const non_copymovable_int &l, int r)
376 { return l.get_int() == r; }
377
378 friend bool operator==(int l, const non_copymovable_int &r)
379 { return l == r.get_int(); }
380
92f5a8d4
TL
381 friend bool operator<(const non_copymovable_int &l, int r)
382 { return l.get_int() < r; }
383
384 friend bool operator<(int l, const non_copymovable_int &r)
385 { return l < r.get_int(); }
386
387 friend std::size_t hash_value(const non_copymovable_int &v)
388 { return (std::size_t)v.get_int(); }
389
7c673cae
FG
390 private:
391 int m_int;
392};
393
394unsigned int non_copymovable_int::count = 0;
395
396template<class T>
397struct life_count
398{
399 static unsigned check(unsigned) { return true; }
400};
401
402template<>
403struct life_count< movable_int >
404{
405 static unsigned check(unsigned c)
406 { return c == movable_int::count; }
407};
408
409template<>
410struct life_count< copyable_int >
411{
412 static unsigned check(unsigned c)
413 { return c == copyable_int::count; }
414};
415
416template<>
417struct life_count< movable_and_copyable_int >
418{
419 static unsigned check(unsigned c)
420 { return c == movable_and_copyable_int::count; }
421};
422
423template<>
424struct life_count< non_copymovable_int >
425{
426 static unsigned check(unsigned c)
427 { return c == non_copymovable_int::count; }
428};
429
430
431} //namespace test {
432} //namespace container {
433} //namespace boost {
434
435#include <boost/container/detail/config_end.hpp>
436
437#endif //#ifndef BOOST_CONTAINER_TEST_MOVABLE_INT_HEADER