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