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_fn2_test.cpp - test for functions w/ the type<> syntax
12 //
13 // Copyright (c) 2005, 2008 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/core/lightweight_test.hpp>
22
23 //
24
25 long global_result;
26
27 // long
28
f_0()29 long f_0()
30 {
31 return global_result = 17041L;
32 }
33
f_1(long a)34 long f_1(long a)
35 {
36 return global_result = a;
37 }
38
f_2(long a,long b)39 long f_2(long a, long b)
40 {
41 return global_result = a + 10 * b;
42 }
43
f_3(long a,long b,long c)44 long f_3(long a, long b, long c)
45 {
46 return global_result = a + 10 * b + 100 * c;
47 }
48
f_4(long a,long b,long c,long d)49 long f_4(long a, long b, long c, long d)
50 {
51 return global_result = a + 10 * b + 100 * c + 1000 * d;
52 }
53
f_5(long a,long b,long c,long d,long e)54 long f_5(long a, long b, long c, long d, long e)
55 {
56 return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
57 }
58
f_6(long a,long b,long c,long d,long e,long f)59 long f_6(long a, long b, long c, long d, long e, long f)
60 {
61 return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
62 }
63
f_7(long a,long b,long c,long d,long e,long f,long g)64 long f_7(long a, long b, long c, long d, long e, long f, long g)
65 {
66 return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
67 }
68
f_8(long a,long b,long c,long d,long e,long f,long g,long h)69 long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
70 {
71 return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
72 }
73
f_9(long a,long b,long c,long d,long e,long f,long g,long h,long i)74 long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
75 {
76 return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
77 }
78
79 // void
80
fv_0()81 void fv_0()
82 {
83 global_result = 17041L;
84 }
85
fv_1(long a)86 void fv_1(long a)
87 {
88 global_result = a;
89 }
90
fv_2(long a,long b)91 void fv_2(long a, long b)
92 {
93 global_result = a + 10 * b;
94 }
95
fv_3(long a,long b,long c)96 void fv_3(long a, long b, long c)
97 {
98 global_result = a + 10 * b + 100 * c;
99 }
100
fv_4(long a,long b,long c,long d)101 void fv_4(long a, long b, long c, long d)
102 {
103 global_result = a + 10 * b + 100 * c + 1000 * d;
104 }
105
fv_5(long a,long b,long c,long d,long e)106 void fv_5(long a, long b, long c, long d, long e)
107 {
108 global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
109 }
110
fv_6(long a,long b,long c,long d,long e,long f)111 void fv_6(long a, long b, long c, long d, long e, long f)
112 {
113 global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
114 }
115
fv_7(long a,long b,long c,long d,long e,long f,long g)116 void fv_7(long a, long b, long c, long d, long e, long f, long g)
117 {
118 global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
119 }
120
fv_8(long a,long b,long c,long d,long e,long f,long g,long h)121 void fv_8(long a, long b, long c, long d, long e, long f, long g, long h)
122 {
123 global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
124 }
125
fv_9(long a,long b,long c,long d,long e,long f,long g,long h,long i)126 void fv_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
127 {
128 global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
129 }
130
function_test()131 void function_test()
132 {
133 using namespace boost;
134
135 bind( type<void>(), f_0 )(); BOOST_TEST( global_result == 17041L );
136 bind( type<void>(), f_1, 1 )(); BOOST_TEST( global_result == 1L );
137 bind( type<void>(), f_2, 1, 2 )(); BOOST_TEST( global_result == 21L );
138 bind( type<void>(), f_3, 1, 2, 3 )(); BOOST_TEST( global_result == 321L );
139 bind( type<void>(), f_4, 1, 2, 3, 4 )(); BOOST_TEST( global_result == 4321L );
140 bind( type<void>(), f_5, 1, 2, 3, 4, 5 )(); BOOST_TEST( global_result == 54321L );
141 bind( type<void>(), f_6, 1, 2, 3, 4, 5, 6 )(); BOOST_TEST( global_result == 654321L );
142 bind( type<void>(), f_7, 1, 2, 3, 4, 5, 6, 7 )(); BOOST_TEST( global_result == 7654321L );
143 bind( type<void>(), f_8, 1, 2, 3, 4, 5, 6, 7, 8 )(); BOOST_TEST( global_result == 87654321L );
144 bind( type<void>(), f_9, 1, 2, 3, 4, 5, 6, 7, 8, 9 )(); BOOST_TEST( global_result == 987654321L );
145
146 bind( type<void>(), fv_0 )(); BOOST_TEST( global_result == 17041L );
147 bind( type<void>(), fv_1, 1 )(); BOOST_TEST( global_result == 1L );
148 bind( type<void>(), fv_2, 1, 2 )(); BOOST_TEST( global_result == 21L );
149 bind( type<void>(), fv_3, 1, 2, 3 )(); BOOST_TEST( global_result == 321L );
150 bind( type<void>(), fv_4, 1, 2, 3, 4 )(); BOOST_TEST( global_result == 4321L );
151 bind( type<void>(), fv_5, 1, 2, 3, 4, 5 )(); BOOST_TEST( global_result == 54321L );
152 bind( type<void>(), fv_6, 1, 2, 3, 4, 5, 6 )(); BOOST_TEST( global_result == 654321L );
153 bind( type<void>(), fv_7, 1, 2, 3, 4, 5, 6, 7 )(); BOOST_TEST( global_result == 7654321L );
154 bind( type<void>(), fv_8, 1, 2, 3, 4, 5, 6, 7, 8 )(); BOOST_TEST( global_result == 87654321L );
155 bind( type<void>(), fv_9, 1, 2, 3, 4, 5, 6, 7, 8, 9 )(); BOOST_TEST( global_result == 987654321L );
156 }
157
main()158 int main()
159 {
160 function_test();
161 return boost::report_errors();
162 }
163