Brian Silverman | ce4aa8d | 2018-08-04 23:36:03 -0700 | [diff] [blame^] | 1 | #include <boost/config.hpp> |
| 2 | |
| 3 | // |
| 4 | // bind_function2_test.cpp - regression test |
| 5 | // |
| 6 | // Copyright (c) 2015 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/function.hpp> |
| 15 | #include <boost/detail/lightweight_test.hpp> |
| 16 | |
| 17 | // |
| 18 | |
| 19 | void fv1( int & a ) |
| 20 | { |
| 21 | a = 17041; |
| 22 | } |
| 23 | |
| 24 | void fv2( int & a, int b ) |
| 25 | { |
| 26 | a = b; |
| 27 | } |
| 28 | |
| 29 | void fv3( int & a, int b, int c ) |
| 30 | { |
| 31 | a = b + c; |
| 32 | } |
| 33 | |
| 34 | void fv4( int & a, int b, int c, int d ) |
| 35 | { |
| 36 | a = b + c + d; |
| 37 | } |
| 38 | |
| 39 | void fv5( int & a, int b, int c, int d, int e ) |
| 40 | { |
| 41 | a = b + c + d + e; |
| 42 | } |
| 43 | |
| 44 | void fv6( int & a, int b, int c, int d, int e, int f ) |
| 45 | { |
| 46 | a = b + c + d + e + f; |
| 47 | } |
| 48 | |
| 49 | void fv7( int & a, int b, int c, int d, int e, int f, int g ) |
| 50 | { |
| 51 | a = b + c + d + e + f + g; |
| 52 | } |
| 53 | |
| 54 | void fv8( int & a, int b, int c, int d, int e, int f, int g, int h ) |
| 55 | { |
| 56 | a = b + c + d + e + f + g + h; |
| 57 | } |
| 58 | |
| 59 | void fv9( int & a, int b, int c, int d, int e, int f, int g, int h, int i ) |
| 60 | { |
| 61 | a = b + c + d + e + f + g + h + i; |
| 62 | } |
| 63 | |
| 64 | void function_test() |
| 65 | { |
| 66 | int x = 0; |
| 67 | |
| 68 | { |
| 69 | boost::function<void(int&)> fw1 = boost::bind( fv1, _1 ); |
| 70 | fw1( x ); BOOST_TEST( x == 17041 ); |
| 71 | } |
| 72 | |
| 73 | { |
| 74 | boost::function<void(int&, int)> fw2 = boost::bind( fv2, _1, _2 ); |
| 75 | fw2( x, 1 ); BOOST_TEST( x == 1 ); |
| 76 | } |
| 77 | |
| 78 | { |
| 79 | boost::function<void(int&, int, int)> fw3 = boost::bind( fv3, _1, _2, _3 ); |
| 80 | fw3( x, 1, 2 ); BOOST_TEST( x == 1+2 ); |
| 81 | } |
| 82 | |
| 83 | { |
| 84 | boost::function<void(int&, int, int, int)> fw4 = boost::bind( fv4, _1, _2, _3, _4 ); |
| 85 | fw4( x, 1, 2, 3 ); BOOST_TEST( x == 1+2+3 ); |
| 86 | } |
| 87 | |
| 88 | { |
| 89 | boost::function<void(int&, int, int, int, int)> fw5 = boost::bind( fv5, _1, _2, _3, _4, _5 ); |
| 90 | fw5( x, 1, 2, 3, 4 ); BOOST_TEST( x == 1+2+3+4 ); |
| 91 | } |
| 92 | |
| 93 | { |
| 94 | boost::function<void(int&, int, int, int, int, int)> fw6 = boost::bind( fv6, _1, _2, _3, _4, _5, _6 ); |
| 95 | fw6( x, 1, 2, 3, 4, 5 ); BOOST_TEST( x == 1+2+3+4+5 ); |
| 96 | } |
| 97 | |
| 98 | { |
| 99 | boost::function<void(int&, int, int, int, int, int, int)> fw7 = boost::bind( fv7, _1, _2, _3, _4, _5, _6, _7 ); |
| 100 | fw7( x, 1, 2, 3, 4, 5, 6 ); BOOST_TEST( x == 1+2+3+4+5+6 ); |
| 101 | } |
| 102 | |
| 103 | { |
| 104 | boost::function<void(int&, int, int, int, int, int, int, int)> fw8 = boost::bind( fv8, _1, _2, _3, _4, _5, _6, _7, _8 ); |
| 105 | fw8( x, 1, 2, 3, 4, 5, 6, 7 ); BOOST_TEST( x == 1+2+3+4+5+6+7 ); |
| 106 | } |
| 107 | |
| 108 | { |
| 109 | boost::function<void(int&, int, int, int, int, int, int, int, int)> fw9 = boost::bind( fv9, _1, _2, _3, _4, _5, _6, _7, _8, _9 ); |
| 110 | fw9( x, 1, 2, 3, 4, 5, 6, 7, 8 ); BOOST_TEST( x == 1+2+3+4+5+6+7+8 ); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | int main() |
| 115 | { |
| 116 | function_test(); |
| 117 | return boost::report_errors(); |
| 118 | } |