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_const_test.cpp - test const bind objects |
---|
12 | // |
---|
13 | // Copyright (c) 2001-2004 Peter Dimov and Multi Media Ltd. |
---|
14 | // Copyright (c) 2001 David Abrahams |
---|
15 | // |
---|
16 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
17 | // accompanying file LICENSE_1_0.txt or copy at |
---|
18 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
19 | // |
---|
20 | |
---|
21 | #include <boost/bind.hpp> |
---|
22 | #include <boost/ref.hpp> |
---|
23 | |
---|
24 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
---|
25 | #pragma warning(push, 3) |
---|
26 | #endif |
---|
27 | |
---|
28 | #include <iostream> |
---|
29 | |
---|
30 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
---|
31 | #pragma warning(pop) |
---|
32 | #endif |
---|
33 | |
---|
34 | #include <boost/detail/lightweight_test.hpp> |
---|
35 | |
---|
36 | // |
---|
37 | |
---|
38 | long f_0() |
---|
39 | { |
---|
40 | return 17041L; |
---|
41 | } |
---|
42 | |
---|
43 | long f_1(long a) |
---|
44 | { |
---|
45 | return a; |
---|
46 | } |
---|
47 | |
---|
48 | long f_2(long a, long b) |
---|
49 | { |
---|
50 | return a + 10 * b; |
---|
51 | } |
---|
52 | |
---|
53 | long f_3(long a, long b, long c) |
---|
54 | { |
---|
55 | return a + 10 * b + 100 * c; |
---|
56 | } |
---|
57 | |
---|
58 | long f_4(long a, long b, long c, long d) |
---|
59 | { |
---|
60 | return a + 10 * b + 100 * c + 1000 * d; |
---|
61 | } |
---|
62 | |
---|
63 | long f_5(long a, long b, long c, long d, long e) |
---|
64 | { |
---|
65 | return a + 10 * b + 100 * c + 1000 * d + 10000 * e; |
---|
66 | } |
---|
67 | |
---|
68 | long f_6(long a, long b, long c, long d, long e, long f) |
---|
69 | { |
---|
70 | return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f; |
---|
71 | } |
---|
72 | |
---|
73 | long f_7(long a, long b, long c, long d, long e, long f, long g) |
---|
74 | { |
---|
75 | return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g; |
---|
76 | } |
---|
77 | |
---|
78 | long f_8(long a, long b, long c, long d, long e, long f, long g, long h) |
---|
79 | { |
---|
80 | return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h; |
---|
81 | } |
---|
82 | |
---|
83 | long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i) |
---|
84 | { |
---|
85 | return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i; |
---|
86 | } |
---|
87 | |
---|
88 | long global_result; |
---|
89 | |
---|
90 | void fv_0() |
---|
91 | { |
---|
92 | global_result = 17041L; |
---|
93 | } |
---|
94 | |
---|
95 | void fv_1(long a) |
---|
96 | { |
---|
97 | global_result = a; |
---|
98 | } |
---|
99 | |
---|
100 | void fv_2(long a, long b) |
---|
101 | { |
---|
102 | global_result = a + 10 * b; |
---|
103 | } |
---|
104 | |
---|
105 | void fv_3(long a, long b, long c) |
---|
106 | { |
---|
107 | global_result = a + 10 * b + 100 * c; |
---|
108 | } |
---|
109 | |
---|
110 | void fv_4(long a, long b, long c, long d) |
---|
111 | { |
---|
112 | global_result = a + 10 * b + 100 * c + 1000 * d; |
---|
113 | } |
---|
114 | |
---|
115 | void fv_5(long a, long b, long c, long d, long e) |
---|
116 | { |
---|
117 | global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e; |
---|
118 | } |
---|
119 | |
---|
120 | void fv_6(long a, long b, long c, long d, long e, long f) |
---|
121 | { |
---|
122 | global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f; |
---|
123 | } |
---|
124 | |
---|
125 | void fv_7(long a, long b, long c, long d, long e, long f, long g) |
---|
126 | { |
---|
127 | global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g; |
---|
128 | } |
---|
129 | |
---|
130 | void fv_8(long a, long b, long c, long d, long e, long f, long g, long h) |
---|
131 | { |
---|
132 | global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h; |
---|
133 | } |
---|
134 | |
---|
135 | void fv_9(long a, long b, long c, long d, long e, long f, long g, long h, long i) |
---|
136 | { |
---|
137 | global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i; |
---|
138 | } |
---|
139 | |
---|
140 | template<class F, class A> long test(F const & f, A const & a) |
---|
141 | { |
---|
142 | return f(a); |
---|
143 | } |
---|
144 | |
---|
145 | template<class F, class A> long testv(F const & f, A const & a) |
---|
146 | { |
---|
147 | f(a); |
---|
148 | return global_result; |
---|
149 | } |
---|
150 | |
---|
151 | void function_test() |
---|
152 | { |
---|
153 | using namespace boost; |
---|
154 | |
---|
155 | int const i = 1; |
---|
156 | |
---|
157 | BOOST_TEST( test( bind(f_0), i ) == 17041L ); |
---|
158 | BOOST_TEST( test( bind(f_1, _1), i ) == 1L ); |
---|
159 | BOOST_TEST( test( bind(f_2, _1, 2), i ) == 21L ); |
---|
160 | BOOST_TEST( test( bind(f_3, _1, 2, 3), i ) == 321L ); |
---|
161 | BOOST_TEST( test( bind(f_4, _1, 2, 3, 4), i ) == 4321L ); |
---|
162 | BOOST_TEST( test( bind(f_5, _1, 2, 3, 4, 5), i ) == 54321L ); |
---|
163 | BOOST_TEST( test( bind(f_6, _1, 2, 3, 4, 5, 6), i ) == 654321L ); |
---|
164 | BOOST_TEST( test( bind(f_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L ); |
---|
165 | BOOST_TEST( test( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L ); |
---|
166 | BOOST_TEST( test( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L ); |
---|
167 | |
---|
168 | BOOST_TEST( testv( bind(fv_0), i ) == 17041L ); |
---|
169 | BOOST_TEST( testv( bind(fv_1, _1), i ) == 1L ); |
---|
170 | BOOST_TEST( testv( bind(fv_2, _1, 2), i ) == 21L ); |
---|
171 | BOOST_TEST( testv( bind(fv_3, _1, 2, 3), i ) == 321L ); |
---|
172 | BOOST_TEST( testv( bind(fv_4, _1, 2, 3, 4), i ) == 4321L ); |
---|
173 | BOOST_TEST( testv( bind(fv_5, _1, 2, 3, 4, 5), i ) == 54321L ); |
---|
174 | BOOST_TEST( testv( bind(fv_6, _1, 2, 3, 4, 5, 6), i ) == 654321L ); |
---|
175 | BOOST_TEST( testv( bind(fv_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L ); |
---|
176 | BOOST_TEST( testv( bind(fv_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L ); |
---|
177 | BOOST_TEST( testv( bind(fv_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L ); |
---|
178 | } |
---|
179 | |
---|
180 | int main() |
---|
181 | { |
---|
182 | function_test(); |
---|
183 | return boost::report_errors(); |
---|
184 | } |
---|