1 | /////////////////////////////////////////////////////////////////////////// |
2 | // |
3 | // (C) Copyright Ion Gaztanaga 2006-2012. 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/interprocess for documentation. |
8 | // |
9 | /////////////////////////////////////////////////////////////////////////// |
10 | |
11 | #ifndef BOOST_INTERPROCESS_TEST_MOVABLE_INT_HEADER |
12 | #define |
13 | |
14 | #include <boost/interprocess/detail/config_begin.hpp> |
15 | #include <boost/interprocess/detail/workaround.hpp> |
16 | #include <boost/move/utility_core.hpp> |
17 | |
18 | namespace boost { |
19 | namespace interprocess { |
20 | namespace test { |
21 | |
22 | template<class T> |
23 | struct is_copyable; |
24 | |
25 | template<> |
26 | struct is_copyable<int> |
27 | { |
28 | static const bool value = true; |
29 | }; |
30 | |
31 | |
32 | class movable_int |
33 | { |
34 | BOOST_MOVABLE_BUT_NOT_COPYABLE(movable_int) |
35 | |
36 | public: |
37 | movable_int() |
38 | : m_int(0) |
39 | {} |
40 | |
41 | explicit movable_int(int a) |
42 | : m_int(a) |
43 | {} |
44 | |
45 | movable_int(BOOST_RV_REF(movable_int) mmi) |
46 | : m_int(mmi.m_int) |
47 | { mmi.m_int = 0; } |
48 | |
49 | movable_int & operator= (BOOST_RV_REF(movable_int) mmi) |
50 | { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; } |
51 | |
52 | movable_int & operator= (int i) |
53 | { this->m_int = i; return *this; } |
54 | |
55 | bool operator ==(const movable_int &mi) const |
56 | { return this->m_int == mi.m_int; } |
57 | |
58 | bool operator !=(const movable_int &mi) const |
59 | { return this->m_int != mi.m_int; } |
60 | |
61 | bool operator <(const movable_int &mi) const |
62 | { return this->m_int < mi.m_int; } |
63 | |
64 | bool operator <=(const movable_int &mi) const |
65 | { return this->m_int <= mi.m_int; } |
66 | |
67 | bool operator >=(const movable_int &mi) const |
68 | { return this->m_int >= mi.m_int; } |
69 | |
70 | bool operator >(const movable_int &mi) const |
71 | { return this->m_int > mi.m_int; } |
72 | |
73 | int get_int() const |
74 | { return m_int; } |
75 | |
76 | friend bool operator==(const movable_int &l, int r) |
77 | { return l.get_int() == r; } |
78 | |
79 | friend bool operator==(int l, const movable_int &r) |
80 | { return l == r.get_int(); } |
81 | |
82 | private: |
83 | int m_int; |
84 | }; |
85 | |
86 | template<class E, class T> |
87 | std::basic_ostream<E, T> & operator<< |
88 | (std::basic_ostream<E, T> & os, movable_int const & p) |
89 | |
90 | { |
91 | os << p.get_int(); |
92 | return os; |
93 | } |
94 | |
95 | |
96 | template<> |
97 | struct is_copyable<movable_int> |
98 | { |
99 | static const bool value = false; |
100 | }; |
101 | |
102 | class movable_and_copyable_int |
103 | { |
104 | BOOST_COPYABLE_AND_MOVABLE(movable_and_copyable_int) |
105 | |
106 | public: |
107 | movable_and_copyable_int() |
108 | : m_int(0) |
109 | {} |
110 | |
111 | explicit movable_and_copyable_int(int a) |
112 | : m_int(a) |
113 | {} |
114 | |
115 | movable_and_copyable_int(const movable_and_copyable_int& mmi) |
116 | : m_int(mmi.m_int) |
117 | {} |
118 | |
119 | movable_and_copyable_int(BOOST_RV_REF(movable_and_copyable_int) mmi) |
120 | : m_int(mmi.m_int) |
121 | { mmi.m_int = 0; } |
122 | |
123 | movable_and_copyable_int &operator= (BOOST_COPY_ASSIGN_REF(movable_and_copyable_int) mi) |
124 | { this->m_int = mi.m_int; return *this; } |
125 | |
126 | movable_and_copyable_int & operator= (BOOST_RV_REF(movable_and_copyable_int) mmi) |
127 | { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; } |
128 | |
129 | movable_and_copyable_int & operator= (int i) |
130 | { this->m_int = i; return *this; } |
131 | |
132 | bool operator ==(const movable_and_copyable_int &mi) const |
133 | { return this->m_int == mi.m_int; } |
134 | |
135 | bool operator !=(const movable_and_copyable_int &mi) const |
136 | { return this->m_int != mi.m_int; } |
137 | |
138 | bool operator <(const movable_and_copyable_int &mi) const |
139 | { return this->m_int < mi.m_int; } |
140 | |
141 | bool operator <=(const movable_and_copyable_int &mi) const |
142 | { return this->m_int <= mi.m_int; } |
143 | |
144 | bool operator >=(const movable_and_copyable_int &mi) const |
145 | { return this->m_int >= mi.m_int; } |
146 | |
147 | bool operator >(const movable_and_copyable_int &mi) const |
148 | { return this->m_int > mi.m_int; } |
149 | |
150 | int get_int() const |
151 | { return m_int; } |
152 | |
153 | friend bool operator==(const movable_and_copyable_int &l, int r) |
154 | { return l.get_int() == r; } |
155 | |
156 | friend bool operator==(int l, const movable_and_copyable_int &r) |
157 | { return l == r.get_int(); } |
158 | |
159 | private: |
160 | int m_int; |
161 | }; |
162 | |
163 | template<class E, class T> |
164 | std::basic_ostream<E, T> & operator<< |
165 | (std::basic_ostream<E, T> & os, movable_and_copyable_int const & p) |
166 | |
167 | { |
168 | os << p.get_int(); |
169 | return os; |
170 | } |
171 | |
172 | template<> |
173 | struct is_copyable<movable_and_copyable_int> |
174 | { |
175 | static const bool value = true; |
176 | }; |
177 | |
178 | class copyable_int |
179 | { |
180 | public: |
181 | copyable_int() |
182 | : m_int(0) |
183 | {} |
184 | |
185 | explicit copyable_int(int a) |
186 | : m_int(a) |
187 | {} |
188 | |
189 | copyable_int(const copyable_int& mmi) |
190 | : m_int(mmi.m_int) |
191 | {} |
192 | |
193 | copyable_int & operator= (int i) |
194 | { this->m_int = i; return *this; } |
195 | |
196 | copyable_int & operator=(const copyable_int& mmi) |
197 | { m_int = mmi.m_int; return *this; } |
198 | |
199 | bool operator ==(const copyable_int &mi) const |
200 | { return this->m_int == mi.m_int; } |
201 | |
202 | bool operator !=(const copyable_int &mi) const |
203 | { return this->m_int != mi.m_int; } |
204 | |
205 | bool operator <(const copyable_int &mi) const |
206 | { return this->m_int < mi.m_int; } |
207 | |
208 | bool operator <=(const copyable_int &mi) const |
209 | { return this->m_int <= mi.m_int; } |
210 | |
211 | bool operator >=(const copyable_int &mi) const |
212 | { return this->m_int >= mi.m_int; } |
213 | |
214 | bool operator >(const copyable_int &mi) const |
215 | { return this->m_int > mi.m_int; } |
216 | |
217 | int get_int() const |
218 | { return m_int; } |
219 | |
220 | friend bool operator==(const copyable_int &l, int r) |
221 | { return l.get_int() == r; } |
222 | |
223 | friend bool operator==(int l, const copyable_int &r) |
224 | { return l == r.get_int(); } |
225 | |
226 | private: |
227 | int m_int; |
228 | }; |
229 | |
230 | template<class E, class T> |
231 | std::basic_ostream<E, T> & operator<< |
232 | (std::basic_ostream<E, T> & os, copyable_int const & p) |
233 | |
234 | { |
235 | os << p.get_int(); |
236 | return os; |
237 | } |
238 | |
239 | template<> |
240 | struct is_copyable<copyable_int> |
241 | { |
242 | static const bool value = true; |
243 | }; |
244 | |
245 | class non_copymovable_int |
246 | { |
247 | non_copymovable_int(const non_copymovable_int& mmi); |
248 | non_copymovable_int & operator= (const non_copymovable_int &mi); |
249 | |
250 | public: |
251 | non_copymovable_int() |
252 | : m_int(0) |
253 | {} |
254 | |
255 | explicit non_copymovable_int(int a) |
256 | : m_int(a) |
257 | {} |
258 | |
259 | bool operator ==(const non_copymovable_int &mi) const |
260 | { return this->m_int == mi.m_int; } |
261 | |
262 | bool operator !=(const non_copymovable_int &mi) const |
263 | { return this->m_int != mi.m_int; } |
264 | |
265 | bool operator <(const non_copymovable_int &mi) const |
266 | { return this->m_int < mi.m_int; } |
267 | |
268 | bool operator <=(const non_copymovable_int &mi) const |
269 | { return this->m_int <= mi.m_int; } |
270 | |
271 | bool operator >=(const non_copymovable_int &mi) const |
272 | { return this->m_int >= mi.m_int; } |
273 | |
274 | bool operator >(const non_copymovable_int &mi) const |
275 | { return this->m_int > mi.m_int; } |
276 | |
277 | int get_int() const |
278 | { return m_int; } |
279 | |
280 | friend bool operator==(const non_copymovable_int &l, int r) |
281 | { return l.get_int() == r; } |
282 | |
283 | friend bool operator==(int l, const non_copymovable_int &r) |
284 | { return l == r.get_int(); } |
285 | |
286 | private: |
287 | int m_int; |
288 | }; |
289 | |
290 | } //namespace test { |
291 | } //namespace interprocess { |
292 | } //namespace boost { |
293 | |
294 | #include <boost/interprocess/detail/config_end.hpp> |
295 | |
296 | #endif //#ifndef BOOST_INTERPROCESS_TEST_MOVABLE_INT_HEADER |
297 | |