File: bind_nested_rv_test.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (179 lines) | stat: -rw-r--r-- 7,814 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <boost/config.hpp>

//
//  bind_nested_rv_test.cpp
//
//  Copyright (c) 2016 Peter Dimov
//
//  Distributed under the Boost Software License, Version 1.0.
//  See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt
//

#include <boost/bind/bind.hpp>
#include <boost/make_shared.hpp>
#include <boost/function.hpp>
#include <boost/core/lightweight_test.hpp>

using namespace boost::placeholders;

//

bool f1( boost::shared_ptr<int> p1 )
{
    BOOST_TEST( p1 != 0 && *p1 == 1 );
    return true;
}

bool f2( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2 )
{
    BOOST_TEST( p1 != 0 && *p1 == 1 );
    BOOST_TEST( p2 != 0 && *p2 == 2 );
    return true;
}

bool f3( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3 )
{
    BOOST_TEST( p1 != 0 && *p1 == 1 );
    BOOST_TEST( p2 != 0 && *p2 == 2 );
    BOOST_TEST( p3 != 0 && *p3 == 3 );
    return true;
}

bool f4( boost::shared_ptr<int> p1, boost::shared_ptr<int> p2, boost::shared_ptr<int> p3, boost::shared_ptr<int> p4 )
{
    BOOST_TEST( p1 != 0 && *p1 == 1 );
    BOOST_TEST( p2 != 0 && *p2 == 2 );
    BOOST_TEST( p3 != 0 && *p3 == 3 );
    BOOST_TEST( p4 != 0 && *p4 == 4 );
    return true;
}

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 )
{
    BOOST_TEST( p1 != 0 && *p1 == 1 );
    BOOST_TEST( p2 != 0 && *p2 == 2 );
    BOOST_TEST( p3 != 0 && *p3 == 3 );
    BOOST_TEST( p4 != 0 && *p4 == 4 );
    BOOST_TEST( p5 != 0 && *p5 == 5 );
    return true;
}

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 )
{
    BOOST_TEST( p1 != 0 && *p1 == 1 );
    BOOST_TEST( p2 != 0 && *p2 == 2 );
    BOOST_TEST( p3 != 0 && *p3 == 3 );
    BOOST_TEST( p4 != 0 && *p4 == 4 );
    BOOST_TEST( p5 != 0 && *p5 == 5 );
    BOOST_TEST( p6 != 0 && *p6 == 6 );
    return true;
}

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 )
{
    BOOST_TEST( p1 != 0 && *p1 == 1 );
    BOOST_TEST( p2 != 0 && *p2 == 2 );
    BOOST_TEST( p3 != 0 && *p3 == 3 );
    BOOST_TEST( p4 != 0 && *p4 == 4 );
    BOOST_TEST( p5 != 0 && *p5 == 5 );
    BOOST_TEST( p6 != 0 && *p6 == 6 );
    BOOST_TEST( p7 != 0 && *p7 == 7 );
    return true;
}

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 )
{
    BOOST_TEST( p1 != 0 && *p1 == 1 );
    BOOST_TEST( p2 != 0 && *p2 == 2 );
    BOOST_TEST( p3 != 0 && *p3 == 3 );
    BOOST_TEST( p4 != 0 && *p4 == 4 );
    BOOST_TEST( p5 != 0 && *p5 == 5 );
    BOOST_TEST( p6 != 0 && *p6 == 6 );
    BOOST_TEST( p7 != 0 && *p7 == 7 );
    BOOST_TEST( p8 != 0 && *p8 == 8 );
    return true;
}

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 )
{
    BOOST_TEST( p1 != 0 && *p1 == 1 );
    BOOST_TEST( p2 != 0 && *p2 == 2 );
    BOOST_TEST( p3 != 0 && *p3 == 3 );
    BOOST_TEST( p4 != 0 && *p4 == 4 );
    BOOST_TEST( p5 != 0 && *p5 == 5 );
    BOOST_TEST( p6 != 0 && *p6 == 6 );
    BOOST_TEST( p7 != 0 && *p7 == 7 );
    BOOST_TEST( p8 != 0 && *p8 == 8 );
    BOOST_TEST( p9 != 0 && *p9 == 9 );
    return true;
}

void test()
{
    {
        boost::function<bool(boost::shared_ptr<int>)> f( f1 );

        ( boost::bind( f, _1 ) && boost::bind( f1, _1 ) )( boost::make_shared<int>( 1 ) );
    }

    {
        boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f2 );

        ( boost::bind( f, _1, _2 ) && boost::bind( f2, _1, _2 ) )( boost::make_shared<int>( 1 ), boost::make_shared<int>( 2 ) );
    }

    {
        boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f3 );

        ( 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 ) );
    }

    {
        boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f3 );

        ( 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 ) );
    }

    {
        boost::function<bool(boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>, boost::shared_ptr<int>)> f( f4 );

        ( 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 ) );
    }

    {
        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 );

        ( 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 ) );
    }

    {
        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 );

        ( 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 ) );
    }

    {
        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 );

        ( 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 ) );
    }

    {
        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 );

        ( 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 ) );
    }

    {
        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 );

        ( 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 ) );
    }
}

int main()
{
    test();
    return boost::report_errors();
}