1 | #include <boost/config.hpp> |
2 | |
3 | #if defined(BOOST_MSVC) |
4 | #pragma warning(disable: 4786) // identifier truncated in debug info |
5 | #pragma warning(disable: 4710) // function not inlined |
6 | #pragma warning(disable: 4711) // function selected for automatic inline expansion |
7 | #pragma warning(disable: 4514) // unreferenced inline removed |
8 | #endif |
9 | |
10 | // |
11 | // bind_eq_test.cpp - boost::bind equality operator |
12 | // |
13 | // Copyright (c) 2004, 2005 Peter Dimov |
14 | // |
15 | // Distributed under the Boost Software License, Version 1.0. (See |
16 | // accompanying file LICENSE_1_0.txt or copy at |
17 | // http://www.boost.org/LICENSE_1_0.txt) |
18 | // |
19 | |
20 | #include <boost/bind/bind.hpp> |
21 | #include <boost/ref.hpp> |
22 | #include <boost/core/lightweight_test.hpp> |
23 | |
24 | using namespace boost::placeholders; |
25 | |
26 | // |
27 | |
28 | struct X |
29 | { |
30 | int i_; |
31 | |
32 | explicit X(int i): i_(i) |
33 | { |
34 | } |
35 | |
36 | bool operator==(X const & rhs) const |
37 | { |
38 | return i_ == rhs.i_; |
39 | } |
40 | }; |
41 | |
42 | // f_* |
43 | |
44 | int f_0() |
45 | { |
46 | return 0; |
47 | } |
48 | |
49 | int f_1(X) |
50 | { |
51 | return 0; |
52 | } |
53 | |
54 | int f_2(X, X) |
55 | { |
56 | return 0; |
57 | } |
58 | |
59 | int f_3(X, X, X) |
60 | { |
61 | return 0; |
62 | } |
63 | |
64 | int f_4(X, X, X, X) |
65 | { |
66 | return 0; |
67 | } |
68 | |
69 | int f_5(X, X, X, X, X) |
70 | { |
71 | return 0; |
72 | } |
73 | |
74 | int f_6(X, X, X, X, X, X) |
75 | { |
76 | return 0; |
77 | } |
78 | |
79 | int f_7(X, X, X, X, X, X, X) |
80 | { |
81 | return 0; |
82 | } |
83 | |
84 | int f_8(X, X, X, X, X, X, X, X) |
85 | { |
86 | return 0; |
87 | } |
88 | |
89 | int f_9(X, X, X, X, X, X, X, X, X) |
90 | { |
91 | return 0; |
92 | } |
93 | |
94 | // fv_* |
95 | |
96 | void fv_0() |
97 | { |
98 | } |
99 | |
100 | void fv_1(X) |
101 | { |
102 | } |
103 | |
104 | void fv_2(X, X) |
105 | { |
106 | } |
107 | |
108 | void fv_3(X, X, X) |
109 | { |
110 | } |
111 | |
112 | void fv_4(X, X, X, X) |
113 | { |
114 | } |
115 | |
116 | void fv_5(X, X, X, X, X) |
117 | { |
118 | } |
119 | |
120 | void fv_6(X, X, X, X, X, X) |
121 | { |
122 | } |
123 | |
124 | void fv_7(X, X, X, X, X, X, X) |
125 | { |
126 | } |
127 | |
128 | void fv_8(X, X, X, X, X, X, X, X) |
129 | { |
130 | } |
131 | |
132 | void fv_9(X, X, X, X, X, X, X, X, X) |
133 | { |
134 | } |
135 | |
136 | template<class F> void test_eq(F f1, F f2) |
137 | { |
138 | BOOST_TEST( function_equal( f1, f2 ) ); |
139 | } |
140 | |
141 | template<class F> void test_ne(F f1, F f2) |
142 | { |
143 | BOOST_TEST( !function_equal( f1, f2 ) ); |
144 | } |
145 | |
146 | // 0 |
147 | |
148 | template<class F> void test_0(F f) |
149 | { |
150 | test_eq( boost::bind(f), boost::bind(f) ); |
151 | } |
152 | |
153 | // 1 |
154 | |
155 | template<class F, class V> void test_1_(F f, V v1, V v2) |
156 | { |
157 | test_eq( boost::bind(f, v1), boost::bind(f, v1) ); |
158 | test_ne( boost::bind(f, v1), boost::bind(f, v2) ); |
159 | } |
160 | |
161 | template<class F> void test_1(F f) |
162 | { |
163 | test_eq( boost::bind(f, _1), boost::bind(f, _1) ); |
164 | |
165 | test_1_( f, X(1), X(2) ); |
166 | |
167 | X a(0), b(0); |
168 | test_1_( f, boost::ref(t&: a), boost::ref(t&: b) ); |
169 | } |
170 | |
171 | // 2 |
172 | |
173 | template<class F, class V> void test_2_(F f, V v1, V v2) |
174 | { |
175 | test_eq( boost::bind(f, v1, v1), boost::bind(f, v1, v1) ); |
176 | test_ne( boost::bind(f, v1, v1), boost::bind(f, v1, v2) ); |
177 | test_ne( boost::bind(f, v1, v1), boost::bind(f, v2, v1) ); |
178 | } |
179 | |
180 | template<class F> void test_2(F f) |
181 | { |
182 | test_eq( boost::bind(f, _1, _2), boost::bind(f, _1, _2) ); |
183 | |
184 | test_2_( f, X(1), X(2) ); |
185 | |
186 | X a(0), b(0); |
187 | test_2_( f, boost::ref(t&: a), boost::ref(t&: b) ); |
188 | } |
189 | |
190 | // 3 |
191 | |
192 | template<class F, class V> void test_3_(F f, V v1, V v2) |
193 | { |
194 | test_eq( boost::bind(f, v1, v1, v1), boost::bind(f, v1, v1, v1) ); |
195 | test_ne( boost::bind(f, v1, v1, v1), boost::bind(f, v1, v1, v2) ); |
196 | test_ne( boost::bind(f, v1, v1, v1), boost::bind(f, v1, v2, v1) ); |
197 | test_ne( boost::bind(f, v1, v1, v1), boost::bind(f, v2, v1, v1) ); |
198 | } |
199 | |
200 | template<class F> void test_3(F f) |
201 | { |
202 | test_eq( boost::bind(f, _1, _2, _3), boost::bind(f, _1, _2, _3) ); |
203 | |
204 | test_3_( f, X(1), X(2) ); |
205 | |
206 | X a(0), b(0); |
207 | test_3_( f, boost::ref(t&: a), boost::ref(t&: b) ); |
208 | } |
209 | |
210 | // 4 |
211 | |
212 | template<class F, class V> void test_4_(F f, V v1, V v2) |
213 | { |
214 | test_eq( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1) ); |
215 | test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2) ); |
216 | test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1) ); |
217 | test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1) ); |
218 | test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1) ); |
219 | } |
220 | |
221 | template<class F> void test_4(F f) |
222 | { |
223 | test_eq( boost::bind(f, _1, _2, _3, _4), boost::bind(f, _1, _2, _3, _4) ); |
224 | |
225 | test_4_( f, X(1), X(2) ); |
226 | |
227 | X a(0), b(0); |
228 | test_4_( f, boost::ref(t&: a), boost::ref(t&: b) ); |
229 | } |
230 | |
231 | // 5 |
232 | |
233 | template<class F, class V> void test_5_(F f, V v1, V v2) |
234 | { |
235 | test_eq( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1) ); |
236 | test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2) ); |
237 | test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1) ); |
238 | test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1) ); |
239 | test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1) ); |
240 | test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1) ); |
241 | } |
242 | |
243 | template<class F> void test_5(F f) |
244 | { |
245 | test_eq( boost::bind(f, _1, _2, _3, _4, _5), boost::bind(f, _1, _2, _3, _4, _5) ); |
246 | |
247 | test_5_( f, X(1), X(2) ); |
248 | |
249 | X a(0), b(0); |
250 | test_5_( f, boost::ref(t&: a), boost::ref(t&: b) ); |
251 | } |
252 | |
253 | // 6 |
254 | |
255 | template<class F, class V> void test_6_(F f, V v1, V v2) |
256 | { |
257 | test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1) ); |
258 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2) ); |
259 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1) ); |
260 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1) ); |
261 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1) ); |
262 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1) ); |
263 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1) ); |
264 | } |
265 | |
266 | template<class F> void test_6(F f) |
267 | { |
268 | test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6), boost::bind(f, _1, _2, _3, _4, _5, _6) ); |
269 | |
270 | test_6_( f, X(1), X(2) ); |
271 | |
272 | X a(0), b(0); |
273 | test_6_( f, boost::ref(t&: a), boost::ref(t&: b) ); |
274 | } |
275 | |
276 | // 7 |
277 | |
278 | template<class F, class V> void test_7_(F f, V v1, V v2) |
279 | { |
280 | test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1) ); |
281 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v2) ); |
282 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2, v1) ); |
283 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1, v1) ); |
284 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1, v1) ); |
285 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1, v1) ); |
286 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1, v1) ); |
287 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1, v1) ); |
288 | } |
289 | |
290 | template<class F> void test_7(F f) |
291 | { |
292 | test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6, _7), boost::bind(f, _1, _2, _3, _4, _5, _6, _7) ); |
293 | |
294 | test_7_( f, X(1), X(2) ); |
295 | |
296 | X a(0), b(0); |
297 | test_7_( f, boost::ref(t&: a), boost::ref(t&: b) ); |
298 | } |
299 | |
300 | // 8 |
301 | |
302 | template<class F, class V> void test_8_(F f, V v1, V v2) |
303 | { |
304 | test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1) ); |
305 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v2) ); |
306 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v2, v1) ); |
307 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2, v1, v1) ); |
308 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1, v1, v1) ); |
309 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1, v1, v1) ); |
310 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1, v1, v1) ); |
311 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1, v1, v1) ); |
312 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1, v1, v1) ); |
313 | } |
314 | |
315 | template<class F> void test_8(F f) |
316 | { |
317 | test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8), boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8) ); |
318 | |
319 | test_8_( f, X(1), X(2) ); |
320 | |
321 | X a(0), b(0); |
322 | test_8_( f, boost::ref(t&: a), boost::ref(t&: b) ); |
323 | } |
324 | |
325 | // 9 |
326 | |
327 | template<class F, class V> void test_9_(F f, V v1, V v2) |
328 | { |
329 | test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1) ); |
330 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v2) ); |
331 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v2, v1) ); |
332 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v2, v1, v1) ); |
333 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2, v1, v1, v1) ); |
334 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1, v1, v1, v1) ); |
335 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1, v1, v1, v1) ); |
336 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1, v1, v1, v1) ); |
337 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1, v1, v1, v1) ); |
338 | test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1, v1, v1, v1) ); |
339 | } |
340 | |
341 | template<class F> void test_9(F f) |
342 | { |
343 | test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8, _9), boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8, _9) ); |
344 | |
345 | test_9_( f, X(1), X(2) ); |
346 | |
347 | X a(0), b(0); |
348 | test_9_( f, boost::ref(t&: a), boost::ref(t&: b) ); |
349 | } |
350 | |
351 | int main() |
352 | { |
353 | // 0 |
354 | |
355 | test_0( f: f_0 ); |
356 | test_0( f: fv_0 ); |
357 | |
358 | // 1 |
359 | |
360 | test_1( f: f_1 ); |
361 | test_1( f: fv_1 ); |
362 | |
363 | // 2 |
364 | |
365 | test_2( f: f_2 ); |
366 | test_2( f: fv_2 ); |
367 | |
368 | // 3 |
369 | |
370 | test_3( f: f_3 ); |
371 | test_3( f: fv_3 ); |
372 | |
373 | // 4 |
374 | |
375 | test_4( f: f_4 ); |
376 | test_4( f: fv_4 ); |
377 | |
378 | // 5 |
379 | |
380 | test_5( f: f_5 ); |
381 | test_5( f: fv_5 ); |
382 | |
383 | // 6 |
384 | |
385 | test_6( f: f_6 ); |
386 | test_6( f: fv_6 ); |
387 | |
388 | // 7 |
389 | |
390 | test_7( f: f_7 ); |
391 | test_7( f: fv_7 ); |
392 | |
393 | // 8 |
394 | |
395 | test_8( f: f_8 ); |
396 | test_8( f: fv_8 ); |
397 | |
398 | // 9 |
399 | |
400 | test_9( f: f_9 ); |
401 | test_9( f: fv_9 ); |
402 | |
403 | return boost::report_errors(); |
404 | } |
405 | |