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