• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 using namespace boost::placeholders;
19 
20 //
21 
f1(boost::shared_ptr<int> p1)22 bool f1( boost::shared_ptr<int> p1 )
23 {
24     BOOST_TEST( p1 != 0 && *p1 == 1 );
25     return true;
26 }
27 
f2(boost::shared_ptr<int> p1,boost::shared_ptr<int> p2)28 bool 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 
f3(boost::shared_ptr<int> p1,boost::shared_ptr<int> p2,boost::shared_ptr<int> p3)35 bool 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 
f4(boost::shared_ptr<int> p1,boost::shared_ptr<int> p2,boost::shared_ptr<int> p3,boost::shared_ptr<int> p4)43 bool 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 
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)52 bool 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 
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)62 bool 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 
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)73 bool 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 
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)85 bool 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 
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)98 bool 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 
test()112 void test()
113 {
114     {
115         boost::function<bool(boost::shared_ptr<int>)> f( f1 );
116 
117         ( boost::bind( f, _1 ) && boost::bind( f1, _1 ) )( boost::make_shared<int>( 1 ) );
118     }
119 
120     {
121         boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f2 );
122 
123         ( boost::bind( f, _1, _2 ) && boost::bind( f2, _1, _2 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 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, _1, _2, _3 ) && boost::bind( f3, _1, _2, _3 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 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, _1, _2, _3 ) && boost::bind( f3, _1, _2, _3 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ), boost::make_shared<int>( 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, _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 ) );
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, _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 ) );
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, _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 ) );
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, _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 ) );
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, _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 ) );
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, _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 ) );
172     }
173 }
174 
main()175 int main()
176 {
177     test();
178     return boost::report_errors();
179 }
180