]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/test/movable_int.hpp
38678d74743225dc00e1c8427bd43a1970b1b592
[ceph.git] / ceph / src / boost / libs / container / test / movable_int.hpp
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
21 namespace boost {
22 namespace container {
23 namespace test {
24
25 template<class T>
26 struct is_copyable;
27
28 template<>
29 struct is_copyable<int>
30 {
31 static const bool value = true;
32 };
33
34
35 class 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
100 private:
101 int m_int;
102 };
103
104 unsigned int movable_int::count = 0;
105
106 inline movable_int produce_movable_int()
107 { return movable_int(); }
108
109 template<class E, class T>
110 std::basic_ostream<E, T> & operator<<
111 (std::basic_ostream<E, T> & os, movable_int const & p)
112
113 {
114 os << p.get_int();
115 return os;
116 }
117
118 template<>
119 struct is_copyable<movable_int>
120 {
121 static const bool value = false;
122 };
123
124 class movable_and_copyable_int
125 {
126 BOOST_COPYABLE_AND_MOVABLE(movable_and_copyable_int)
127
128 public:
129
130 static unsigned int count;
131
132 movable_and_copyable_int()
133 : m_int(0)
134 { ++count; }
135
136 explicit movable_and_copyable_int(int a)
137 : m_int(a)
138 {
139 //Disallow INT_MIN
140 BOOST_ASSERT(this->m_int != INT_MIN);
141 ++count;
142 }
143
144 movable_and_copyable_int(const movable_and_copyable_int& mmi)
145 : m_int(mmi.m_int)
146 { ++count; }
147
148 movable_and_copyable_int(BOOST_RV_REF(movable_and_copyable_int) mmi)
149 : m_int(mmi.m_int)
150 { mmi.m_int = 0; ++count; }
151
152 ~movable_and_copyable_int()
153 {
154 //Double destructor called
155 BOOST_ASSERT(this->m_int != INT_MIN);
156 this->m_int = INT_MIN;
157 --count;
158 }
159
160 movable_and_copyable_int &operator= (BOOST_COPY_ASSIGN_REF(movable_and_copyable_int) mi)
161 { this->m_int = mi.m_int; return *this; }
162
163 movable_and_copyable_int & operator= (BOOST_RV_REF(movable_and_copyable_int) mmi)
164 { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; }
165
166 movable_and_copyable_int & operator= (int i)
167 { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
168
169 friend bool operator ==(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
170 { return l.m_int == r.m_int; }
171
172 friend bool operator !=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
173 { return l.m_int != r.m_int; }
174
175 friend bool operator <(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
176 { return l.m_int < r.m_int; }
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 int get_int() const
188 { return m_int; }
189
190 friend bool operator==(const movable_and_copyable_int &l, int r)
191 { return l.get_int() == r; }
192
193 friend bool operator==(int l, const movable_and_copyable_int &r)
194 { return l == r.get_int(); }
195
196 private:
197 int m_int;
198 };
199
200 unsigned int movable_and_copyable_int::count = 0;
201
202 inline movable_and_copyable_int produce_movable_and_copyable_int()
203 { return movable_and_copyable_int(); }
204
205 template<class E, class T>
206 std::basic_ostream<E, T> & operator<<
207 (std::basic_ostream<E, T> & os, movable_and_copyable_int const & p)
208
209 {
210 os << p.get_int();
211 return os;
212 }
213
214 template<>
215 struct is_copyable<movable_and_copyable_int>
216 {
217 static const bool value = true;
218 };
219
220 class copyable_int
221 {
222 public:
223
224 static unsigned int count;
225
226 copyable_int()
227 : m_int(0)
228 { ++count; }
229
230 explicit copyable_int(int a)
231 : m_int(a)
232 {
233 //Disallow INT_MIN
234 BOOST_ASSERT(this->m_int != INT_MIN);
235 ++count;
236 }
237
238 copyable_int(const copyable_int& mmi)
239 : m_int(mmi.m_int)
240 { ++count; }
241
242 copyable_int & operator= (int i)
243 { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
244
245 copyable_int & operator= (const copyable_int &ci)
246 { this->m_int = ci.m_int; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
247
248 ~copyable_int()
249 {
250 //Double destructor called
251 BOOST_ASSERT(this->m_int != INT_MIN);
252 this->m_int = INT_MIN;
253 --count;
254 }
255
256 friend bool operator ==(const copyable_int &l, const copyable_int &r)
257 { return l.m_int == r.m_int; }
258
259 friend bool operator !=(const copyable_int &l, const copyable_int &r)
260 { return l.m_int != r.m_int; }
261
262 friend bool operator <(const copyable_int &l, const copyable_int &r)
263 { return l.m_int < r.m_int; }
264
265 friend bool operator <=(const copyable_int &l, const copyable_int &r)
266 { return l.m_int <= r.m_int; }
267
268 friend bool operator >=(const copyable_int &l, const copyable_int &r)
269 { return l.m_int >= r.m_int; }
270
271 friend bool operator >(const copyable_int &l, const copyable_int &r)
272 { return l.m_int > r.m_int; }
273
274 int get_int() const
275 { return m_int; }
276
277 friend bool operator==(const copyable_int &l, int r)
278 { return l.get_int() == r; }
279
280 friend bool operator==(int l, const copyable_int &r)
281 { return l == r.get_int(); }
282
283 private:
284 int m_int;
285 };
286
287 unsigned int copyable_int::count = 0;
288
289 inline copyable_int produce_copyable_int()
290 { return copyable_int(); }
291
292 template<class E, class T>
293 std::basic_ostream<E, T> & operator<<
294 (std::basic_ostream<E, T> & os, copyable_int const & p)
295
296 {
297 os << p.get_int();
298 return os;
299 }
300
301 template<>
302 struct is_copyable<copyable_int>
303 {
304 static const bool value = true;
305 };
306
307 class non_copymovable_int
308 {
309 non_copymovable_int(const non_copymovable_int& mmi);
310 non_copymovable_int & operator= (const non_copymovable_int &mi);
311
312 public:
313
314 static unsigned int count;
315
316 non_copymovable_int()
317 : m_int(0)
318 { ++count; }
319
320 explicit non_copymovable_int(int a)
321 : m_int(a)
322 { ++count; }
323
324 ~non_copymovable_int()
325 { m_int = 0; --count; }
326
327 bool operator ==(const non_copymovable_int &mi) const
328 { return this->m_int == mi.m_int; }
329
330 bool operator !=(const non_copymovable_int &mi) const
331 { return this->m_int != mi.m_int; }
332
333 bool operator <(const non_copymovable_int &mi) const
334 { return this->m_int < mi.m_int; }
335
336 bool operator <=(const non_copymovable_int &mi) const
337 { return this->m_int <= mi.m_int; }
338
339 bool operator >=(const non_copymovable_int &mi) const
340 { return this->m_int >= mi.m_int; }
341
342 bool operator >(const non_copymovable_int &mi) const
343 { return this->m_int > mi.m_int; }
344
345 int get_int() const
346 { return m_int; }
347
348 friend bool operator==(const non_copymovable_int &l, int r)
349 { return l.get_int() == r; }
350
351 friend bool operator==(int l, const non_copymovable_int &r)
352 { return l == r.get_int(); }
353
354 private:
355 int m_int;
356 };
357
358 unsigned int non_copymovable_int::count = 0;
359
360 template<class T>
361 struct life_count
362 {
363 static unsigned check(unsigned) { return true; }
364 };
365
366 template<>
367 struct life_count< movable_int >
368 {
369 static unsigned check(unsigned c)
370 { return c == movable_int::count; }
371 };
372
373 template<>
374 struct life_count< copyable_int >
375 {
376 static unsigned check(unsigned c)
377 { return c == copyable_int::count; }
378 };
379
380 template<>
381 struct life_count< movable_and_copyable_int >
382 {
383 static unsigned check(unsigned c)
384 { return c == movable_and_copyable_int::count; }
385 };
386
387 template<>
388 struct life_count< non_copymovable_int >
389 {
390 static unsigned check(unsigned c)
391 { return c == non_copymovable_int::count; }
392 };
393
394
395 } //namespace test {
396 } //namespace container {
397 } //namespace boost {
398
399 #include <boost/container/detail/config_end.hpp>
400
401 #endif //#ifndef BOOST_CONTAINER_TEST_MOVABLE_INT_HEADER