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