1 ///////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/container for documentation.
9 ///////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_CONTAINER_TEST_MOVABLE_INT_HEADER
12 #define BOOST_CONTAINER_TEST_MOVABLE_INT_HEADER
14 #include <boost/container/detail/config_begin.hpp>
15 #include <boost/container/detail/workaround.hpp>
16 #include <boost/move/utility_core.hpp>
19 #include <boost/assert.hpp>
29 struct is_copyable<int>
31 static const bool value = true;
37 BOOST_MOVABLE_BUT_NOT_COPYABLE(movable_int)
41 static unsigned int count;
47 explicit movable_int(int a)
51 BOOST_ASSERT(this->m_int != INT_MIN);
55 movable_int(BOOST_RV_REF(movable_int) mmi)
57 { mmi.m_int = 0; ++count; }
59 movable_int & operator= (BOOST_RV_REF(movable_int) mmi)
60 { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; }
62 movable_int & operator= (int i)
63 { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
67 //Double destructor called
68 BOOST_ASSERT(this->m_int != INT_MIN);
69 this->m_int = INT_MIN;
73 friend bool operator ==(const movable_int &l, const movable_int &r)
74 { return l.m_int == r.m_int; }
76 friend bool operator !=(const movable_int &l, const movable_int &r)
77 { return l.m_int != r.m_int; }
79 friend bool operator <(const movable_int &l, const movable_int &r)
80 { return l.m_int < r.m_int; }
82 friend bool operator <=(const movable_int &l, const movable_int &r)
83 { return l.m_int <= r.m_int; }
85 friend bool operator >=(const movable_int &l, const movable_int &r)
86 { return l.m_int >= r.m_int; }
88 friend bool operator >(const movable_int &l, const movable_int &r)
89 { return l.m_int > r.m_int; }
94 friend bool operator==(const movable_int &l, int r)
95 { return l.get_int() == r; }
97 friend bool operator==(int l, const movable_int &r)
98 { return l == r.get_int(); }
104 unsigned int movable_int::count = 0;
106 inline movable_int produce_movable_int()
107 { return movable_int(); }
109 template<class E, class T>
110 std::basic_ostream<E, T> & operator<<
111 (std::basic_ostream<E, T> & os, movable_int const & p)
119 struct is_copyable<movable_int>
121 static const bool value = false;
124 class movable_and_copyable_int
126 BOOST_COPYABLE_AND_MOVABLE(movable_and_copyable_int)
130 static unsigned int count;
132 movable_and_copyable_int()
136 explicit movable_and_copyable_int(int a)
140 BOOST_ASSERT(this->m_int != INT_MIN);
144 movable_and_copyable_int(const movable_and_copyable_int& mmi)
148 movable_and_copyable_int(BOOST_RV_REF(movable_and_copyable_int) mmi)
150 { mmi.m_int = 0; ++count; }
152 ~movable_and_copyable_int()
154 //Double destructor called
155 BOOST_ASSERT(this->m_int != INT_MIN);
156 this->m_int = INT_MIN;
160 movable_and_copyable_int &operator= (BOOST_COPY_ASSIGN_REF(movable_and_copyable_int) mi)
161 { this->m_int = mi.m_int; return *this; }
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; }
166 movable_and_copyable_int & operator= (int i)
167 { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
169 friend bool operator ==(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
170 { return l.m_int == r.m_int; }
172 friend bool operator !=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
173 { return l.m_int != r.m_int; }
175 friend bool operator <(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
176 { return l.m_int < r.m_int; }
178 friend bool operator <=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
179 { return l.m_int <= r.m_int; }
181 friend bool operator >=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
182 { return l.m_int >= r.m_int; }
184 friend bool operator >(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
185 { return l.m_int > r.m_int; }
190 friend bool operator==(const movable_and_copyable_int &l, int r)
191 { return l.get_int() == r; }
193 friend bool operator==(int l, const movable_and_copyable_int &r)
194 { return l == r.get_int(); }
200 unsigned int movable_and_copyable_int::count = 0;
202 inline movable_and_copyable_int produce_movable_and_copyable_int()
203 { return movable_and_copyable_int(); }
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)
215 struct is_copyable<movable_and_copyable_int>
217 static const bool value = true;
224 static unsigned int count;
230 explicit copyable_int(int a)
234 BOOST_ASSERT(this->m_int != INT_MIN);
238 copyable_int(const copyable_int& mmi)
242 copyable_int & operator= (int i)
243 { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
245 copyable_int & operator= (const copyable_int &ci)
246 { this->m_int = ci.m_int; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
250 //Double destructor called
251 BOOST_ASSERT(this->m_int != INT_MIN);
252 this->m_int = INT_MIN;
256 friend bool operator ==(const copyable_int &l, const copyable_int &r)
257 { return l.m_int == r.m_int; }
259 friend bool operator !=(const copyable_int &l, const copyable_int &r)
260 { return l.m_int != r.m_int; }
262 friend bool operator <(const copyable_int &l, const copyable_int &r)
263 { return l.m_int < r.m_int; }
265 friend bool operator <=(const copyable_int &l, const copyable_int &r)
266 { return l.m_int <= r.m_int; }
268 friend bool operator >=(const copyable_int &l, const copyable_int &r)
269 { return l.m_int >= r.m_int; }
271 friend bool operator >(const copyable_int &l, const copyable_int &r)
272 { return l.m_int > r.m_int; }
277 friend bool operator==(const copyable_int &l, int r)
278 { return l.get_int() == r; }
280 friend bool operator==(int l, const copyable_int &r)
281 { return l == r.get_int(); }
287 unsigned int copyable_int::count = 0;
289 inline copyable_int produce_copyable_int()
290 { return copyable_int(); }
292 template<class E, class T>
293 std::basic_ostream<E, T> & operator<<
294 (std::basic_ostream<E, T> & os, copyable_int const & p)
302 struct is_copyable<copyable_int>
304 static const bool value = true;
307 class non_copymovable_int
309 non_copymovable_int(const non_copymovable_int& mmi);
310 non_copymovable_int & operator= (const non_copymovable_int &mi);
314 static unsigned int count;
316 non_copymovable_int()
320 explicit non_copymovable_int(int a)
324 ~non_copymovable_int()
325 { m_int = 0; --count; }
327 bool operator ==(const non_copymovable_int &mi) const
328 { return this->m_int == mi.m_int; }
330 bool operator !=(const non_copymovable_int &mi) const
331 { return this->m_int != mi.m_int; }
333 bool operator <(const non_copymovable_int &mi) const
334 { return this->m_int < mi.m_int; }
336 bool operator <=(const non_copymovable_int &mi) const
337 { return this->m_int <= mi.m_int; }
339 bool operator >=(const non_copymovable_int &mi) const
340 { return this->m_int >= mi.m_int; }
342 bool operator >(const non_copymovable_int &mi) const
343 { return this->m_int > mi.m_int; }
348 friend bool operator==(const non_copymovable_int &l, int r)
349 { return l.get_int() == r; }
351 friend bool operator==(int l, const non_copymovable_int &r)
352 { return l == r.get_int(); }
358 unsigned int non_copymovable_int::count = 0;
363 static unsigned check(unsigned) { return true; }
367 struct life_count< movable_int >
369 static unsigned check(unsigned c)
370 { return c == movable_int::count; }
374 struct life_count< copyable_int >
376 static unsigned check(unsigned c)
377 { return c == copyable_int::count; }
381 struct life_count< movable_and_copyable_int >
383 static unsigned check(unsigned c)
384 { return c == movable_and_copyable_int::count; }
388 struct life_count< non_copymovable_int >
390 static unsigned check(unsigned c)
391 { return c == non_copymovable_int::count; }
396 } //namespace container {
397 } //namespace boost {
399 #include <boost/container/detail/config_end.hpp>
401 #endif //#ifndef BOOST_CONTAINER_TEST_MOVABLE_INT_HEADER