]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/boost_bind_compatibility/bind_stateful_test.cpp
1 /*==============================================================================
2 Copyright (c) 2004 Peter Dimov
3 Copyright (c) 2005-2010 Joel de Guzman
4 Copyright (c) 2010 Thomas Heller
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 ==============================================================================*/
10 #include <boost/config.hpp>
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
19 #include <boost/phoenix/core.hpp>
20 #include <boost/phoenix/bind.hpp>
22 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
23 #pragma warning(push, 3)
28 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
32 #include <boost/detail/lightweight_test.hpp>
51 typedef int result_type
;
53 int operator()() const
55 return state_
+= 17041;
58 int operator()(int x1
) const
63 int operator()(int x1
, int x2
) const
65 return state_
+= x1
+x2
;
68 int operator()(int x1
, int x2
, int x3
) const
70 return state_
+= x1
+x2
+x3
;
73 int operator()(int x1
, int x2
, int x3
, int x4
) const
75 return state_
+= x1
+x2
+x3
+x4
;
78 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
) const
80 return state_
+= x1
+x2
+x3
+x4
+x5
;
83 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
) const
85 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
;
88 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
) const
90 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
;
93 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
, int x8
) const
95 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
+x8
;
98 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
, int x8
, int x9
) const
100 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
+x8
+x9
;
121 typedef int result_type
;
125 return state_
+= 17041;
128 int operator()(int x1
)
133 int operator()(int x1
, int x2
)
135 return state_
+= x1
+x2
;
138 int operator()(int x1
, int x2
, int x3
)
140 return state_
+= x1
+x2
+x3
;
143 int operator()(int x1
, int x2
, int x3
, int x4
)
145 return state_
+= x1
+x2
+x3
+x4
;
148 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
)
150 return state_
+= x1
+x2
+x3
+x4
+x5
;
153 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
)
155 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
;
158 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
)
160 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
;
163 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
, int x8
)
165 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
+x8
;
168 int operator()(int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
, int x8
, int x9
)
170 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
+x8
+x9
;
176 return state_
+= 17041;
179 int f1(int & state_
, int x1
)
184 int f2(int & state_
, int x1
, int x2
)
186 return state_
+= x1
+x2
;
189 int f3(int & state_
, int x1
, int x2
, int x3
)
191 return state_
+= x1
+x2
+x3
;
194 int f4(int & state_
, int x1
, int x2
, int x3
, int x4
)
196 return state_
+= x1
+x2
+x3
+x4
;
199 int f5(int & state_
, int x1
, int x2
, int x3
, int x4
, int x5
)
201 return state_
+= x1
+x2
+x3
+x4
+x5
;
204 int f6(int & state_
, int x1
, int x2
, int x3
, int x4
, int x5
, int x6
)
206 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
;
209 int f7(int & state_
, int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
)
211 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
;
214 int f8(int & state_
, int x1
, int x2
, int x3
, int x4
, int x5
, int x6
, int x7
, int x8
)
216 return state_
+= x1
+x2
+x3
+x4
+x5
+x6
+x7
+x8
;
219 template <typename
> struct wrap
{};
221 template<class F
> void test(F f
, int a
, int b
)
223 BOOST_TEST( f() == a
+ b
);
224 BOOST_TEST( f() == a
+ 2*b
);
225 BOOST_TEST( f() == a
+ 3*b
);
228 using boost::phoenix::bind
;
229 using boost::phoenix::ref
;
231 void stateful_function_object_test()
233 ::test( bind( X() ), 0, 17041 );
234 ::test( bind( X(), 1 ), 0, 1 );
235 ::test( bind( X(), 1, 2 ), 0, 1+2 );
236 ::test( bind( X(), 1, 2, 3 ), 0, 1+2+3 );
237 ::test( bind( X(), 1, 2, 3, 4 ), 0, 1+2+3+4 );
238 ::test( bind( X(), 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 );
239 ::test( bind( X(), 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 );
240 ::test( bind( X(), 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 );
241 ::test( bind( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 );
242 ::test( bind( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 0, 1+2+3+4+5+6+7+8+9 );
248 ::test( bind( ref(y
) ), n
, 17041 );
251 ::test( bind( ref(y
), 1 ), n
, 1 );
254 ::test( bind( ref(y
), 1, 2 ), n
, 1+2 );
257 ::test( bind( ref(y
), 1, 2, 3 ), n
, 1+2+3 );
260 ::test( bind( ref(y
), 1, 2, 3, 4 ), n
, 1+2+3+4 );
263 ::test( bind( ref(y
), 1, 2, 3, 4, 5 ), n
, 1+2+3+4+5 );
266 ::test( bind( ref(y
), 1, 2, 3, 4, 5, 6 ), n
, 1+2+3+4+5+6 );
267 n
+= 3*(1+2+3+4+5+6);
269 ::test( bind( ref(y
), 1, 2, 3, 4, 5, 6, 7 ), n
, 1+2+3+4+5+6+7 );
270 n
+= 3*(1+2+3+4+5+6+7);
272 ::test( bind( ref(y
), 1, 2, 3, 4, 5, 6, 7, 8 ), n
, 1+2+3+4+5+6+7+8 );
273 n
+= 3*(1+2+3+4+5+6+7+8);
275 ::test( bind( ref(y
), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), n
, 1+2+3+4+5+6+7+8+9 );
276 n
+= 3*(1+2+3+4+5+6+7+8+9);
278 BOOST_TEST( y
.state() == n
);
281 void stateful_function_test()
283 using boost::phoenix::ref
;
285 ::test( bind( f0
, 0), 0, 17041 );
286 ::test( bind( f1
, 0, 1 ), 0, 1 );
287 ::test( bind( f2
, 0, 1, 2 ), 0, 1+2 );
288 ::test( bind( f3
, 0, 1, 2, 3 ), 0, 1+2+3 );
289 ::test( bind( f4
, 0, 1, 2, 3, 4 ), 0, 1+2+3+4 );
290 ::test( bind( f5
, 0, 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 );
291 ::test( bind( f6
, 0, 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 );
292 ::test( bind( f7
, 0, 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 );
293 ::test( bind( f8
, 0, 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 );
298 stateful_function_object_test();
299 stateful_function_test();
300 return boost::report_errors();