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