1 #include <boost/config.hpp>
2
3 //
4 // bind_fwd2_test.cpp - forwarding test for 2 arguments
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.hpp>
14 #include <boost/detail/lightweight_test.hpp>
15
16 //
17
fv1(int const & a)18 int fv1( int const & a )
19 {
20 return a;
21 }
22
fv2_1(int & a,int const & b)23 void fv2_1( int & a, int const & b )
24 {
25 a = b;
26 }
27
fv2_2(int const & a,int & b)28 void fv2_2( int const & a, int & b )
29 {
30 b = a;
31 }
32
fv2_3(int const & a,int const & b)33 int fv2_3( int const & a, int const & b )
34 {
35 return a+b;
36 }
37
test()38 void test()
39 {
40 {
41 int const a = 1;
42 int r = boost::bind( fv1, _1 )( a );
43 BOOST_TEST( r == 1 );
44 }
45
46 {
47 int r = boost::bind( fv1, _1 )( 1 );
48 BOOST_TEST( r == 1 );
49 }
50
51 {
52 int a = 1;
53 int const b = 2;
54
55 boost::bind( fv2_1, _1, _2 )( a, b );
56
57 BOOST_TEST( a == 2 );
58 }
59
60 {
61 int a = 1;
62
63 boost::bind( fv2_1, _1, _2 )( a, 2 );
64
65 BOOST_TEST( a == 2 );
66 }
67
68 {
69 int const a = 1;
70 int b = 2;
71
72 boost::bind( fv2_2, _1, _2 )( a, b );
73
74 BOOST_TEST( b == 1 );
75 }
76
77 {
78 int b = 2;
79
80 boost::bind( fv2_2, _1, _2 )( 1, b );
81
82 BOOST_TEST( b == 1 );
83 }
84
85 {
86 int const a = 1;
87 int const b = 2;
88
89 int r = boost::bind( fv2_3, _1, _2 )( a, b );
90
91 BOOST_TEST( r == 3 );
92 }
93
94 {
95 int const a = 1;
96
97 int r = boost::bind( fv2_3, _1, _2 )( a, 2 );
98
99 BOOST_TEST( r == 3 );
100 }
101
102 {
103 int const b = 2;
104
105 int r = boost::bind( fv2_3, _1, _2 )( 1, b );
106
107 BOOST_TEST( r == 3 );
108 }
109
110 {
111 int r = boost::bind( fv2_3, _1, _2 )( 1, 2 );
112
113 BOOST_TEST( r == 3 );
114 }
115 }
116
main()117 int main()
118 {
119 test();
120 return boost::report_errors();
121 }
122