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

source code of boost/libs/bind/test/bind_function2_test.cpp