1#include <boost/config.hpp>
2
3//
4// bind_nested_rv_test.cpp
5//
6// Copyright (c) 2016 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/make_shared.hpp>
15#include <boost/function.hpp>
16#include <boost/core/lightweight_test.hpp>
17
18using namespace boost::placeholders;
19
20//
21
22bool f1( boost::shared_ptr<int> p1 )
23{
24 BOOST_TEST( p1 != 0 && *p1 == 1 );
25 return true;
26}
27
28bool f2( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2 )
29{
30 BOOST_TEST( p1 != 0 && *p1 == 1 );
31 BOOST_TEST( p2 != 0 && *p2 == 2 );
32 return true;
33}
34
35bool f3( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3 )
36{
37 BOOST_TEST( p1 != 0 && *p1 == 1 );
38 BOOST_TEST( p2 != 0 && *p2 == 2 );
39 BOOST_TEST( p3 != 0 && *p3 == 3 );
40 return true;
41}
42
43bool f4( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4 )
44{
45 BOOST_TEST( p1 != 0 && *p1 == 1 );
46 BOOST_TEST( p2 != 0 && *p2 == 2 );
47 BOOST_TEST( p3 != 0 && *p3 == 3 );
48 BOOST_TEST( p4 != 0 && *p4 == 4 );
49 return true;
50}
51
52bool f5( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5 )
53{
54 BOOST_TEST( p1 != 0 && *p1 == 1 );
55 BOOST_TEST( p2 != 0 && *p2 == 2 );
56 BOOST_TEST( p3 != 0 && *p3 == 3 );
57 BOOST_TEST( p4 != 0 && *p4 == 4 );
58 BOOST_TEST( p5 != 0 && *p5 == 5 );
59 return true;
60}
61
62bool f6( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6 )
63{
64 BOOST_TEST( p1 != 0 && *p1 == 1 );
65 BOOST_TEST( p2 != 0 && *p2 == 2 );
66 BOOST_TEST( p3 != 0 && *p3 == 3 );
67 BOOST_TEST( p4 != 0 && *p4 == 4 );
68 BOOST_TEST( p5 != 0 && *p5 == 5 );
69 BOOST_TEST( p6 != 0 && *p6 == 6 );
70 return true;
71}
72
73bool f7( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6, boost::shared_ptr<int> p7 )
74{
75 BOOST_TEST( p1 != 0 && *p1 == 1 );
76 BOOST_TEST( p2 != 0 && *p2 == 2 );
77 BOOST_TEST( p3 != 0 && *p3 == 3 );
78 BOOST_TEST( p4 != 0 && *p4 == 4 );
79 BOOST_TEST( p5 != 0 && *p5 == 5 );
80 BOOST_TEST( p6 != 0 && *p6 == 6 );
81 BOOST_TEST( p7 != 0 && *p7 == 7 );
82 return true;
83}
84
85bool f8( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6, boost::shared_ptr<int> p7, boost::shared_ptr<int> p8 )
86{
87 BOOST_TEST( p1 != 0 && *p1 == 1 );
88 BOOST_TEST( p2 != 0 && *p2 == 2 );
89 BOOST_TEST( p3 != 0 && *p3 == 3 );
90 BOOST_TEST( p4 != 0 && *p4 == 4 );
91 BOOST_TEST( p5 != 0 && *p5 == 5 );
92 BOOST_TEST( p6 != 0 && *p6 == 6 );
93 BOOST_TEST( p7 != 0 && *p7 == 7 );
94 BOOST_TEST( p8 != 0 && *p8 == 8 );
95 return true;
96}
97
98bool f9( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4, boost::shared_ptr<int> p5, boost::shared_ptr<int> p6, boost::shared_ptr<int> p7, boost::shared_ptr<int> p8, boost::shared_ptr<int> p9 )
99{
100 BOOST_TEST( p1 != 0 && *p1 == 1 );
101 BOOST_TEST( p2 != 0 && *p2 == 2 );
102 BOOST_TEST( p3 != 0 && *p3 == 3 );
103 BOOST_TEST( p4 != 0 && *p4 == 4 );
104 BOOST_TEST( p5 != 0 && *p5 == 5 );
105 BOOST_TEST( p6 != 0 && *p6 == 6 );
106 BOOST_TEST( p7 != 0 && *p7 == 7 );
107 BOOST_TEST( p8 != 0 && *p8 == 8 );
108 BOOST_TEST( p9 != 0 && *p9 == 9 );
109 return true;
110}
111
112void test()
113{
114 {
115 boost::function<bool(boost::shared_ptr<int>)> f( f1 );
116
117 ( boost::bind( f, a: _1 ) && boost::bind( f: f1, a1: _1 ) )( boost::make_shared<int>( args: 1 ) );
118 }
119
120 {
121 boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f2 );
122
123 ( boost::bind( f, a: _1, a: _2 ) && boost::bind( f: f2, a1: _1, a2: _2 ) )( boost::make_shared<int>( args: 1 ), boost::make_shared<int>( args: 2 ) );
124 }
125
126 {
127 boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f3 );
128
129 ( boost::bind( f, a: _1, a: _2, a: _3 ) && boost::bind( f: f3, a1: _1, a2: _2, a3: _3 ) )( boost::make_shared<int>( args: 1 ), boost::make_shared<int>( args: 2 ), boost::make_shared<int>( args: 3 ) );
130 }
131
132 {
133 boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f3 );
134
135 ( boost::bind( f, a: _1, a: _2, a: _3 ) && boost::bind( f: f3, a1: _1, a2: _2, a3: _3 ) )( boost::make_shared<int>( args: 1 ), boost::make_shared<int>( args: 2 ), boost::make_shared<int>( args: 3 ) );
136 }
137
138 {
139 boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f4 );
140
141 ( boost::bind( f, a: _1, a: _2, a: _3, a: _4 ) && boost::bind( f: f4, a1: _1, a2: _2, a3: _3, a4: _4 ) )( boost::make_shared<int>( args: 1 ), boost::make_shared<int>( args: 2 ), boost::make_shared<int>( args: 3 ), boost::make_shared<int>( args: 4 ) );
142 }
143
144 {
145 boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f5 );
146
147 ( boost::bind( f, a: _1, a: _2, a: _3, a: _4, a: _5 ) && boost::bind( f: f5, a1: _1, a2: _2, a3: _3, a4: _4, a5: _5 ) )( boost::make_shared<int>( args: 1 ), boost::make_shared<int>( args: 2 ), boost::make_shared<int>( args: 3 ), boost::make_shared<int>( args: 4 ), boost::make_shared<int>( args: 5 ) );
148 }
149
150 {
151 boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f6 );
152
153 ( boost::bind( f, a: _1, a: _2, a: _3, a: _4, a: _5, a: _6 ) && boost::bind( f: f6, a1: _1, a2: _2, a3: _3, a4: _4, a5: _5, a6: _6 ) )( boost::make_shared<int>( args: 1 ), boost::make_shared<int>( args: 2 ), boost::make_shared<int>( args: 3 ), boost::make_shared<int>( args: 4 ), boost::make_shared<int>( args: 5 ), boost::make_shared<int>( args: 6 ) );
154 }
155
156 {
157 boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f7 );
158
159 ( boost::bind( f, a: _1, a: _2, a: _3, a: _4, a: _5, a: _6, a: _7 ) && boost::bind( f: f7, a1: _1, a2: _2, a3: _3, a4: _4, a5: _5, a6: _6, a7: _7 ) )( boost::make_shared<int>( args: 1 ), boost::make_shared<int>( args: 2 ), boost::make_shared<int>( args: 3 ), boost::make_shared<int>( args: 4 ), boost::make_shared<int>( args: 5 ), boost::make_shared<int>( args: 6 ), boost::make_shared<int>( args: 7 ) );
160 }
161
162 {
163 boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f8 );
164
165 ( boost::bind( f, a: _1, a: _2, a: _3, a: _4, a: _5, a: _6, a: _7, a: _8 ) && boost::bind( f: f8, a1: _1, a2: _2, a3: _3, a4: _4, a5: _5, a6: _6, a7: _7, a8: _8 ) )( boost::make_shared<int>( args: 1 ), boost::make_shared<int>( args: 2 ), boost::make_shared<int>( args: 3 ), boost::make_shared<int>( args: 4 ), boost::make_shared<int>( args: 5 ), boost::make_shared<int>( args: 6 ), boost::make_shared<int>( args: 7 ), boost::make_shared<int>( args: 8 ) );
166 }
167
168 {
169 boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f9 );
170
171 ( boost::bind( f, a: _1, a: _2, a: _3, a: _4, a: _5, a: _6, a: _7, a: _8, a: _9 ) && boost::bind( f: f9, a1: _1, a2: _2, a3: _3, a4: _4, a5: _5, a6: _6, a7: _7, a8: _8, a9: _9 ) )( boost::make_shared<int>( args: 1 ), boost::make_shared<int>( args: 2 ), boost::make_shared<int>( args: 3 ), boost::make_shared<int>( args: 4 ), boost::make_shared<int>( args: 5 ), boost::make_shared<int>( args: 6 ), boost::make_shared<int>( args: 7 ), boost::make_shared<int>( args: 8 ), boost::make_shared<int>( args: 9 ) );
172 }
173}
174
175int main()
176{
177 test();
178 return boost::report_errors();
179}
180

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