1 #include <boost/config.hpp>
2
3 //
4 // bind_function2_test.cpp - regression test
5 //
6 // Copyright (c) 2015 Peter Dimov
7 //
8 // Distributed under the Boost Software License, Version 1.0.
9 // See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt
11 //
12
13 #include <boost/bind/bind.hpp>
14 #include <boost/function.hpp>
15 #include <boost/core/lightweight_test.hpp>
16
17 using namespace boost::placeholders;
18
19 //
20
fv1(int & a)21 void fv1( int & a )
22 {
23 a = 17041;
24 }
25
fv2(int & a,int b)26 void fv2( int & a, int b )
27 {
28 a = b;
29 }
30
fv3(int & a,int b,int c)31 void fv3( int & a, int b, int c )
32 {
33 a = b + c;
34 }
35
fv4(int & a,int b,int c,int d)36 void fv4( int & a, int b, int c, int d )
37 {
38 a = b + c + d;
39 }
40
fv5(int & a,int b,int c,int d,int e)41 void fv5( int & a, int b, int c, int d, int e )
42 {
43 a = b + c + d + e;
44 }
45
fv6(int & a,int b,int c,int d,int e,int f)46 void fv6( int & a, int b, int c, int d, int e, int f )
47 {
48 a = b + c + d + e + f;
49 }
50
fv7(int & a,int b,int c,int d,int e,int f,int g)51 void fv7( int & a, int b, int c, int d, int e, int f, int g )
52 {
53 a = b + c + d + e + f + g;
54 }
55
fv8(int & a,int b,int c,int d,int e,int f,int g,int h)56 void fv8( int & a, int b, int c, int d, int e, int f, int g, int h )
57 {
58 a = b + c + d + e + f + g + h;
59 }
60
fv9(int & a,int b,int c,int d,int e,int f,int g,int h,int i)61 void fv9( int & a, int b, int c, int d, int e, int f, int g, int h, int i )
62 {
63 a = b + c + d + e + f + g + h + i;
64 }
65
function_test()66 void function_test()
67 {
68 int x = 0;
69
70 {
71 boost::function<void(int&)> fw1 = boost::bind( fv1, _1 );
72 fw1( x ); BOOST_TEST( x == 17041 );
73 }
74
75 {
76 boost::function<void(int&, int)> fw2 = boost::bind( fv2, _1, _2 );
77 fw2( x, 1 ); BOOST_TEST( x == 1 );
78 }
79
80 {
81 boost::function<void(int&, int, int)> fw3 = boost::bind( fv3, _1, _2, _3 );
82 fw3( x, 1, 2 ); BOOST_TEST( x == 1+2 );
83 }
84
85 {
86 boost::function<void(int&, int, int, int)> fw4 = boost::bind( fv4, _1, _2, _3, _4 );
87 fw4( x, 1, 2, 3 ); BOOST_TEST( x == 1+2+3 );
88 }
89
90 {
91 boost::function<void(int&, int, int, int, int)> fw5 = boost::bind( fv5, _1, _2, _3, _4, _5 );
92 fw5( x, 1, 2, 3, 4 ); BOOST_TEST( x == 1+2+3+4 );
93 }
94
95 {
96 boost::function<void(int&, int, int, int, int, int)> fw6 = boost::bind( fv6, _1, _2, _3, _4, _5, _6 );
97 fw6( x, 1, 2, 3, 4, 5 ); BOOST_TEST( x == 1+2+3+4+5 );
98 }
99
100 {
101 boost::function<void(int&, int, int, int, int, int, int)> fw7 = boost::bind( fv7, _1, _2, _3, _4, _5, _6, _7 );
102 fw7( x, 1, 2, 3, 4, 5, 6 ); BOOST_TEST( x == 1+2+3+4+5+6 );
103 }
104
105 {
106 boost::function<void(int&, int, int, int, int, int, int, int)> fw8 = boost::bind( fv8, _1, _2, _3, _4, _5, _6, _7, _8 );
107 fw8( x, 1, 2, 3, 4, 5, 6, 7 ); BOOST_TEST( x == 1+2+3+4+5+6+7 );
108 }
109
110 {
111 boost::function<void(int&, int, int, int, int, int, int, int, int)> fw9 = boost::bind( fv9, _1, _2, _3, _4, _5, _6, _7, _8, _9 );
112 fw9( x, 1, 2, 3, 4, 5, 6, 7, 8 ); BOOST_TEST( x == 1+2+3+4+5+6+7+8 );
113 }
114 }
115
main()116 int main()
117 {
118 function_test();
119 return boost::report_errors();
120 }
121