]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/bind/test/bind_stateful_test.cpp
1 #include <boost/config.hpp>
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
11 // bind_stateful_test.cpp
13 // Copyright (c) 2004 Peter Dimov
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)
20 #include <boost/bind/bind.hpp>
21 #include <boost/core/lightweight_test.hpp>
37 // SGI-related compilers have odd compiler-synthesized ctors and dtors
49 return state_
+= 17041;
52 int operator()(int x1
)
57 int operator()(int x1
, int x2
)
59 return state_
+= x1
+x2
;
62 int operator()(int x1
, int x2
, int x3
)
64 return state_
+= x1
+x2
+x3
;
67 int operator()(int x1
, int x2
, int x3
, int x4
)
69 return state_
+= x1
+x2
+x3
+x4
;
72 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
)
74 return state_
+= x1
+x2
+x3
+x4
+x5
;
77 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
)
79 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
;
82 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
)
84 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
;
87 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
, int x8
)
89 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
+x8
;
92 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
, int x8
, int x9
)
94 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
+x8
+x9
;
100 return state_
+= 17041;
103 int f1(int & state_
, int x1
)
108 int f2(int & state_
, int x1
, int x2
)
110 return state_
+= x1
+x2
;
113 int f3(int & state_
, int x1
, int x2
, int x3
)
115 return state_
+= x1
+x2
+x3
;
118 int f4(int & state_
, int x1
, int x2
, int x3
, int x4
)
120 return state_
+= x1
+x2
+x3
+x4
;
123 int f5(int & state_
, int x1
, int x2
, int x3
, int x4
, int x5
)
125 return state_
+= x1
+x2
+x3
+x4
+x5
;
128 int f6(int & state_
, int x1
, int x2
, int x3
, int x4
, int x5
, int x6
)
130 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
;
133 int f7(int & state_
, int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
)
135 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
;
138 int f8(int & state_
, int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
, int x8
)
140 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
+x8
;
143 template<class F
> void test(F f
, int a
, int b
)
145 BOOST_TEST( f() == a
+ b
);
146 BOOST_TEST( f() == a
+ 2*b
);
147 BOOST_TEST( f() == a
+ 3*b
);
150 void stateful_function_object_test()
152 test( boost::bind
<int>( X() ), 0, 17041 );
153 test( boost::bind
<int>( X(), 1 ), 0, 1 );
154 test( boost::bind
<int>( X(), 1, 2 ), 0, 1+2 );
155 test( boost::bind
<int>( X(), 1, 2, 3 ), 0, 1+2+3 );
156 test( boost::bind
<int>( X(), 1, 2, 3, 4 ), 0, 1+2+3+4 );
157 test( boost::bind
<int>( X(), 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 );
158 test( boost::bind
<int>( X(), 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 );
159 test( boost::bind
<int>( X(), 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 );
160 test( boost::bind
<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 );
161 test( boost::bind
<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 0, 1+2+3+4+5+6+7+8+9 );
167 test( boost::bind
<int>( boost::ref(x
) ), n
, 17041 );
170 test( boost::bind
<int>( boost::ref(x
), 1 ), n
, 1 );
173 test( boost::bind
<int>( boost::ref(x
), 1, 2 ), n
, 1+2 );
176 test( boost::bind
<int>( boost::ref(x
), 1, 2, 3 ), n
, 1+2+3 );
179 test( boost::bind
<int>( boost::ref(x
), 1, 2, 3, 4 ), n
, 1+2+3+4 );
182 test( boost::bind
<int>( boost::ref(x
), 1, 2, 3, 4, 5 ), n
, 1+2+3+4+5 );
185 test( boost::bind
<int>( boost::ref(x
), 1, 2, 3, 4, 5, 6 ), n
, 1+2+3+4+5+6 );
186 n
+= 3*(1+2+3+4+5+6);
188 test( boost::bind
<int>( boost::ref(x
), 1, 2, 3, 4, 5, 6, 7 ), n
, 1+2+3+4+5+6+7 );
189 n
+= 3*(1+2+3+4+5+6+7);
191 test( boost::bind
<int>( boost::ref(x
), 1, 2, 3, 4, 5, 6, 7, 8 ), n
, 1+2+3+4+5+6+7+8 );
192 n
+= 3*(1+2+3+4+5+6+7+8);
194 test( boost::bind
<int>( boost::ref(x
), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), n
, 1+2+3+4+5+6+7+8+9 );
195 n
+= 3*(1+2+3+4+5+6+7+8+9);
197 BOOST_TEST( x
.state() == n
);
200 void stateful_function_test()
202 test( boost::bind( f0
, 0 ), 0, 17041 );
203 test( boost::bind( f1
, 0, 1 ), 0, 1 );
204 test( boost::bind( f2
, 0, 1, 2 ), 0, 1+2 );
205 test( boost::bind( f3
, 0, 1, 2, 3 ), 0, 1+2+3 );
206 test( boost::bind( f4
, 0, 1, 2, 3, 4 ), 0, 1+2+3+4 );
207 test( boost::bind( f5
, 0, 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 );
208 test( boost::bind( f6
, 0, 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 );
209 test( boost::bind( f7
, 0, 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 );
210 test( boost::bind( f8
, 0, 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 );
215 stateful_function_object_test();
216 stateful_function_test();
217 return boost::report_errors();