| 1 | #include <boost/config.hpp> |
| 2 | #include <boost/config/pragma_message.hpp> |
| 3 | |
| 4 | // |
| 5 | // bind_function_ap_test.cpp - regression test |
| 6 | // |
| 7 | // Copyright (c) 2015 Peter Dimov |
| 8 | // |
| 9 | // Distributed under the Boost Software License, Version 1.0. |
| 10 | // See accompanying file LICENSE_1_0.txt or copy at |
| 11 | // http://www.boost.org/LICENSE_1_0.txt |
| 12 | // |
| 13 | |
| 14 | #if defined(BOOST_NO_AUTO_PTR) |
| 15 | |
| 16 | BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_AUTO_PTR is defined" ) |
| 17 | int main() {} |
| 18 | |
| 19 | #elif !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ( defined(BOOST_GCC) && BOOST_GCC < 40600 ) |
| 20 | |
| 21 | BOOST_PRAGMA_MESSAGE( "Skipping test for GCC 4.4 -std=c++0x" ) |
| 22 | int main() {} |
| 23 | |
| 24 | #else |
| 25 | |
| 26 | #if defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 406 ) |
| 27 | # pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 28 | #elif defined( __clang__ ) && defined( __has_warning ) |
| 29 | # if __has_warning( "-Wdeprecated-declarations" ) |
| 30 | # pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 31 | # endif |
| 32 | #endif |
| 33 | |
| 34 | #include <boost/bind/bind.hpp> |
| 35 | #include <boost/function.hpp> |
| 36 | #include <boost/core/lightweight_test.hpp> |
| 37 | #include <memory> |
| 38 | |
| 39 | using namespace boost::placeholders; |
| 40 | |
| 41 | // |
| 42 | |
| 43 | void fv1( std::auto_ptr<int> p1 ) |
| 44 | { |
| 45 | BOOST_TEST( *p1 == 1 ); |
| 46 | } |
| 47 | |
| 48 | void fv2( std::auto_ptr<int> p1, std::auto_ptr<int> p2 ) |
| 49 | { |
| 50 | BOOST_TEST( *p1 == 1 ); |
| 51 | BOOST_TEST( *p2 == 2 ); |
| 52 | } |
| 53 | |
| 54 | void fv3( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3 ) |
| 55 | { |
| 56 | BOOST_TEST( *p1 == 1 ); |
| 57 | BOOST_TEST( *p2 == 2 ); |
| 58 | BOOST_TEST( *p3 == 3 ); |
| 59 | } |
| 60 | |
| 61 | void fv4( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4 ) |
| 62 | { |
| 63 | BOOST_TEST( *p1 == 1 ); |
| 64 | BOOST_TEST( *p2 == 2 ); |
| 65 | BOOST_TEST( *p3 == 3 ); |
| 66 | BOOST_TEST( *p4 == 4 ); |
| 67 | } |
| 68 | |
| 69 | void fv5( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5 ) |
| 70 | { |
| 71 | BOOST_TEST( *p1 == 1 ); |
| 72 | BOOST_TEST( *p2 == 2 ); |
| 73 | BOOST_TEST( *p3 == 3 ); |
| 74 | BOOST_TEST( *p4 == 4 ); |
| 75 | BOOST_TEST( *p5 == 5 ); |
| 76 | } |
| 77 | |
| 78 | void fv6( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6 ) |
| 79 | { |
| 80 | BOOST_TEST( *p1 == 1 ); |
| 81 | BOOST_TEST( *p2 == 2 ); |
| 82 | BOOST_TEST( *p3 == 3 ); |
| 83 | BOOST_TEST( *p4 == 4 ); |
| 84 | BOOST_TEST( *p5 == 5 ); |
| 85 | BOOST_TEST( *p6 == 6 ); |
| 86 | } |
| 87 | |
| 88 | void fv7( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6, std::auto_ptr<int> p7 ) |
| 89 | { |
| 90 | BOOST_TEST( *p1 == 1 ); |
| 91 | BOOST_TEST( *p2 == 2 ); |
| 92 | BOOST_TEST( *p3 == 3 ); |
| 93 | BOOST_TEST( *p4 == 4 ); |
| 94 | BOOST_TEST( *p5 == 5 ); |
| 95 | BOOST_TEST( *p6 == 6 ); |
| 96 | BOOST_TEST( *p7 == 7 ); |
| 97 | } |
| 98 | |
| 99 | void fv8( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6, std::auto_ptr<int> p7, std::auto_ptr<int> p8 ) |
| 100 | { |
| 101 | BOOST_TEST( *p1 == 1 ); |
| 102 | BOOST_TEST( *p2 == 2 ); |
| 103 | BOOST_TEST( *p3 == 3 ); |
| 104 | BOOST_TEST( *p4 == 4 ); |
| 105 | BOOST_TEST( *p5 == 5 ); |
| 106 | BOOST_TEST( *p6 == 6 ); |
| 107 | BOOST_TEST( *p7 == 7 ); |
| 108 | BOOST_TEST( *p8 == 8 ); |
| 109 | } |
| 110 | |
| 111 | void fv9( std::auto_ptr<int> p1, std::auto_ptr<int> p2, std::auto_ptr<int> p3, std::auto_ptr<int> p4, std::auto_ptr<int> p5, std::auto_ptr<int> p6, std::auto_ptr<int> p7, std::auto_ptr<int> p8, std::auto_ptr<int> p9 ) |
| 112 | { |
| 113 | BOOST_TEST( *p1 == 1 ); |
| 114 | BOOST_TEST( *p2 == 2 ); |
| 115 | BOOST_TEST( *p3 == 3 ); |
| 116 | BOOST_TEST( *p4 == 4 ); |
| 117 | BOOST_TEST( *p5 == 5 ); |
| 118 | BOOST_TEST( *p6 == 6 ); |
| 119 | BOOST_TEST( *p7 == 7 ); |
| 120 | BOOST_TEST( *p8 == 8 ); |
| 121 | BOOST_TEST( *p9 == 9 ); |
| 122 | } |
| 123 | |
| 124 | void test() |
| 125 | { |
| 126 | { |
| 127 | boost::function<void(std::auto_ptr<int>)> fw1 = boost::bind( f: fv1, a1: _1 ); |
| 128 | |
| 129 | std::auto_ptr<int> p1( new int(1) ); |
| 130 | |
| 131 | fw1( p1 ); |
| 132 | } |
| 133 | |
| 134 | { |
| 135 | boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>)> fw2 = boost::bind( f: fv2, a1: _1, a2: _2 ); |
| 136 | |
| 137 | std::auto_ptr<int> p1( new int(1) ); |
| 138 | std::auto_ptr<int> p2( new int(2) ); |
| 139 | |
| 140 | fw2( p1, p2 ); |
| 141 | } |
| 142 | |
| 143 | { |
| 144 | boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw3 = boost::bind( f: fv3, a1: _1, a2: _2, a3: _3 ); |
| 145 | |
| 146 | std::auto_ptr<int> p1( new int(1) ); |
| 147 | std::auto_ptr<int> p2( new int(2) ); |
| 148 | std::auto_ptr<int> p3( new int(3) ); |
| 149 | |
| 150 | fw3( p1, p2, p3 ); |
| 151 | } |
| 152 | |
| 153 | { |
| 154 | boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw4 = boost::bind( f: fv4, a1: _1, a2: _2, a3: _3, a4: _4 ); |
| 155 | |
| 156 | std::auto_ptr<int> p1( new int(1) ); |
| 157 | std::auto_ptr<int> p2( new int(2) ); |
| 158 | std::auto_ptr<int> p3( new int(3) ); |
| 159 | std::auto_ptr<int> p4( new int(4) ); |
| 160 | |
| 161 | fw4( p1, p2, p3, p4 ); |
| 162 | } |
| 163 | |
| 164 | { |
| 165 | boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw5 = boost::bind( f: fv5, a1: _1, a2: _2, a3: _3, a4: _4, a5: _5 ); |
| 166 | |
| 167 | std::auto_ptr<int> p1( new int(1) ); |
| 168 | std::auto_ptr<int> p2( new int(2) ); |
| 169 | std::auto_ptr<int> p3( new int(3) ); |
| 170 | std::auto_ptr<int> p4( new int(4) ); |
| 171 | std::auto_ptr<int> p5( new int(5) ); |
| 172 | |
| 173 | fw5( p1, p2, p3, p4, p5 ); |
| 174 | } |
| 175 | |
| 176 | { |
| 177 | boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw6 = boost::bind( f: fv6, a1: _1, a2: _2, a3: _3, a4: _4, a5: _5, a6: _6 ); |
| 178 | |
| 179 | std::auto_ptr<int> p1( new int(1) ); |
| 180 | std::auto_ptr<int> p2( new int(2) ); |
| 181 | std::auto_ptr<int> p3( new int(3) ); |
| 182 | std::auto_ptr<int> p4( new int(4) ); |
| 183 | std::auto_ptr<int> p5( new int(5) ); |
| 184 | std::auto_ptr<int> p6( new int(6) ); |
| 185 | |
| 186 | fw6( p1, p2, p3, p4, p5, p6 ); |
| 187 | } |
| 188 | |
| 189 | { |
| 190 | boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw7 = boost::bind( f: fv7, a1: _1, a2: _2, a3: _3, a4: _4, a5: _5, a6: _6, a7: _7 ); |
| 191 | |
| 192 | std::auto_ptr<int> p1( new int(1) ); |
| 193 | std::auto_ptr<int> p2( new int(2) ); |
| 194 | std::auto_ptr<int> p3( new int(3) ); |
| 195 | std::auto_ptr<int> p4( new int(4) ); |
| 196 | std::auto_ptr<int> p5( new int(5) ); |
| 197 | std::auto_ptr<int> p6( new int(6) ); |
| 198 | std::auto_ptr<int> p7( new int(7) ); |
| 199 | |
| 200 | fw7( p1, p2, p3, p4, p5, p6, p7 ); |
| 201 | } |
| 202 | |
| 203 | { |
| 204 | boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw8 = boost::bind( f: fv8, a1: _1, a2: _2, a3: _3, a4: _4, a5: _5, a6: _6, a7: _7, a8: _8 ); |
| 205 | |
| 206 | std::auto_ptr<int> p1( new int(1) ); |
| 207 | std::auto_ptr<int> p2( new int(2) ); |
| 208 | std::auto_ptr<int> p3( new int(3) ); |
| 209 | std::auto_ptr<int> p4( new int(4) ); |
| 210 | std::auto_ptr<int> p5( new int(5) ); |
| 211 | std::auto_ptr<int> p6( new int(6) ); |
| 212 | std::auto_ptr<int> p7( new int(7) ); |
| 213 | std::auto_ptr<int> p8( new int(8) ); |
| 214 | |
| 215 | fw8( p1, p2, p3, p4, p5, p6, p7, p8 ); |
| 216 | } |
| 217 | |
| 218 | { |
| 219 | boost::function<void(std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>, std::auto_ptr<int>)> fw9 = boost::bind( f: fv9, a1: _1, a2: _2, a3: _3, a4: _4, a5: _5, a6: _6, a7: _7, a8: _8, a9: _9 ); |
| 220 | |
| 221 | std::auto_ptr<int> p1( new int(1) ); |
| 222 | std::auto_ptr<int> p2( new int(2) ); |
| 223 | std::auto_ptr<int> p3( new int(3) ); |
| 224 | std::auto_ptr<int> p4( new int(4) ); |
| 225 | std::auto_ptr<int> p5( new int(5) ); |
| 226 | std::auto_ptr<int> p6( new int(6) ); |
| 227 | std::auto_ptr<int> p7( new int(7) ); |
| 228 | std::auto_ptr<int> p8( new int(8) ); |
| 229 | std::auto_ptr<int> p9( new int(9) ); |
| 230 | |
| 231 | fw9( p1, p2, p3, p4, p5, p6, p7, p8, p9 ); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | int main() |
| 236 | { |
| 237 | test(); |
| 238 | return boost::report_errors(); |
| 239 | } |
| 240 | |
| 241 | #endif |
| 242 | |