| 1 | #include <boost/config.hpp> |
| 2 | |
| 3 | #if defined(BOOST_MSVC) |
| 4 | #pragma warning(disable: 4786) // identifier truncated in debug info |
| 5 | #pragma warning(disable: 4710) // function not inlined |
| 6 | #pragma warning(disable: 4711) // function selected for automatic inline expansion |
| 7 | #pragma warning(disable: 4514) // unreferenced inline removed |
| 8 | #endif |
| 9 | |
| 10 | // |
| 11 | // bind_cv_test.cpp |
| 12 | // |
| 13 | // Copyright (c) 2004 Peter Dimov |
| 14 | // |
| 15 | // Distributed under the Boost Software License, Version 1.0. (See |
| 16 | // accompanying file LICENSE_1_0.txt or copy at |
| 17 | // http://www.boost.org/LICENSE_1_0.txt) |
| 18 | // |
| 19 | |
| 20 | #include <boost/bind/bind.hpp> |
| 21 | #include <boost/core/lightweight_test.hpp> |
| 22 | |
| 23 | // |
| 24 | |
| 25 | struct X |
| 26 | { |
| 27 | // SGI-related compilers have odd compiler-synthesized ctors dtors |
| 28 | #ifdef __PATHSCALE__ |
| 29 | X() {} |
| 30 | ~X() {} |
| 31 | #endif |
| 32 | |
| 33 | int operator()() |
| 34 | { |
| 35 | return 17041; |
| 36 | } |
| 37 | |
| 38 | int operator()() const |
| 39 | { |
| 40 | return -17041; |
| 41 | } |
| 42 | |
| 43 | int operator()(int x1) |
| 44 | { |
| 45 | return x1; |
| 46 | } |
| 47 | |
| 48 | int operator()(int x1) const |
| 49 | { |
| 50 | return -x1; |
| 51 | } |
| 52 | |
| 53 | int operator()(int x1, int x2) |
| 54 | { |
| 55 | return x1+x2; |
| 56 | } |
| 57 | |
| 58 | int operator()(int x1, int x2) const |
| 59 | { |
| 60 | return -(x1+x2); |
| 61 | } |
| 62 | |
| 63 | int operator()(int x1, int x2, int x3) |
| 64 | { |
| 65 | return x1+x2+x3; |
| 66 | } |
| 67 | |
| 68 | int operator()(int x1, int x2, int x3) const |
| 69 | { |
| 70 | return -(x1+x2+x3); |
| 71 | } |
| 72 | |
| 73 | int operator()(int x1, int x2, int x3, int x4) |
| 74 | { |
| 75 | return x1+x2+x3+x4; |
| 76 | } |
| 77 | |
| 78 | int operator()(int x1, int x2, int x3, int x4) const |
| 79 | { |
| 80 | return -(x1+x2+x3+x4); |
| 81 | } |
| 82 | |
| 83 | int operator()(int x1, int x2, int x3, int x4, int x5) |
| 84 | { |
| 85 | return x1+x2+x3+x4+x5; |
| 86 | } |
| 87 | |
| 88 | int operator()(int x1, int x2, int x3, int x4, int x5) const |
| 89 | { |
| 90 | return -(x1+x2+x3+x4+x5); |
| 91 | } |
| 92 | |
| 93 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6) |
| 94 | { |
| 95 | return x1+x2+x3+x4+x5+x6; |
| 96 | } |
| 97 | |
| 98 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6) const |
| 99 | { |
| 100 | return -(x1+x2+x3+x4+x5+x6); |
| 101 | } |
| 102 | |
| 103 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) |
| 104 | { |
| 105 | return x1+x2+x3+x4+x5+x6+x7; |
| 106 | } |
| 107 | |
| 108 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) const |
| 109 | { |
| 110 | return -(x1+x2+x3+x4+x5+x6+x7); |
| 111 | } |
| 112 | |
| 113 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) |
| 114 | { |
| 115 | return x1+x2+x3+x4+x5+x6+x7+x8; |
| 116 | } |
| 117 | |
| 118 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) const |
| 119 | { |
| 120 | return -(x1+x2+x3+x4+x5+x6+x7+x8); |
| 121 | } |
| 122 | |
| 123 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) |
| 124 | { |
| 125 | return x1+x2+x3+x4+x5+x6+x7+x8+x9; |
| 126 | } |
| 127 | |
| 128 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const |
| 129 | { |
| 130 | return -(x1+x2+x3+x4+x5+x6+x7+x8+x9); |
| 131 | } |
| 132 | }; |
| 133 | |
| 134 | template<class F> void test(F f, int r) |
| 135 | { |
| 136 | F const & cf = f; |
| 137 | BOOST_TEST( cf() == -r ); |
| 138 | BOOST_TEST( f() == r ); |
| 139 | } |
| 140 | |
| 141 | int main() |
| 142 | { |
| 143 | test( f: boost::bind<int>( f: X() ), r: 17041 ); |
| 144 | test( f: boost::bind<int>( f: X(), a1: 1 ), r: 1 ); |
| 145 | test( f: boost::bind<int>( f: X(), a1: 1, a2: 2 ), r: 1+2 ); |
| 146 | test( f: boost::bind<int>( f: X(), a1: 1, a2: 2, a3: 3 ), r: 1+2+3 ); |
| 147 | test( f: boost::bind<int>( f: X(), a1: 1, a2: 2, a3: 3, a4: 4 ), r: 1+2+3+4 ); |
| 148 | test( f: boost::bind<int>( f: X(), a1: 1, a2: 2, a3: 3, a4: 4, a5: 5 ), r: 1+2+3+4+5 ); |
| 149 | test( f: boost::bind<int>( f: X(), a1: 1, a2: 2, a3: 3, a4: 4, a5: 5, a6: 6 ), r: 1+2+3+4+5+6 ); |
| 150 | test( f: boost::bind<int>( f: X(), a1: 1, a2: 2, a3: 3, a4: 4, a5: 5, a6: 6, a7: 7 ), r: 1+2+3+4+5+6+7 ); |
| 151 | test( f: boost::bind<int>( f: X(), a1: 1, a2: 2, a3: 3, a4: 4, a5: 5, a6: 6, a7: 7, a8: 8 ), r: 1+2+3+4+5+6+7+8 ); |
| 152 | test( f: boost::bind<int>( f: X(), a1: 1, a2: 2, a3: 3, a4: 4, a5: 5, a6: 6, a7: 7, a8: 8, a9: 9 ), r: 1+2+3+4+5+6+7+8+9 ); |
| 153 | |
| 154 | return boost::report_errors(); |
| 155 | } |
| 156 | |