1 
2 // Copyright 2018 Peter Dimov.
3 // Distributed under the Boost Software License, Version 1.0.
4 
5 #include <boost/function.hpp>
6 #include <boost/core/lightweight_test.hpp>
7 
8 //
9 
10 void call_fn_1( boost::function<void()> const & fn );
11 void call_fn_2( boost::function<void(int)> const & fn );
12 void call_fn_3( boost::function<void(int, int)> const & fn );
13 
14 void call_fn_4( boost::function0<void> const & fn );
15 void call_fn_5( boost::function1<void, int> const & fn );
16 void call_fn_6( boost::function2<void, int, int> const & fn );
17 
18 //
19 
20 static int v;
21 
f0()22 void f0()
23 {
24     v = -1;
25 }
26 
f1(int x)27 void f1( int x )
28 {
29     v = x;
30 }
31 
f2(int x,int y)32 void f2( int x, int y )
33 {
34     v = x + y;
35 }
36 
main()37 int main()
38 {
39     v = 0; call_fn_1( f0 ); BOOST_TEST_EQ( v, -1 );
40     v = 0; call_fn_2( f1 ); BOOST_TEST_EQ( v, 1 );
41     v = 0; call_fn_3( f2 ); BOOST_TEST_EQ( v, 3 );
42 
43     v = 0; call_fn_4( f0 ); BOOST_TEST_EQ( v, -1 );
44     v = 0; call_fn_5( f1 ); BOOST_TEST_EQ( v, 1 );
45     v = 0; call_fn_6( f2 ); BOOST_TEST_EQ( v, 3 );
46 
47     return boost::report_errors();
48 }
49