| 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.hpp> |
|---|
| 21 | |
|---|
| 22 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
|---|
| 23 | #pragma warning(push, 3) |
|---|
| 24 | #endif |
|---|
| 25 | |
|---|
| 26 | #include <iostream> |
|---|
| 27 | |
|---|
| 28 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
|---|
| 29 | #pragma warning(pop) |
|---|
| 30 | #endif |
|---|
| 31 | |
|---|
| 32 | #include <boost/detail/lightweight_test.hpp> |
|---|
| 33 | |
|---|
| 34 | struct X |
|---|
| 35 | { |
|---|
| 36 | int operator()() |
|---|
| 37 | { |
|---|
| 38 | return 17041; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | int operator()() const |
|---|
| 42 | { |
|---|
| 43 | return -17041; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | int operator()(int x1) |
|---|
| 47 | { |
|---|
| 48 | return x1; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | int operator()(int x1) const |
|---|
| 52 | { |
|---|
| 53 | return -x1; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | int operator()(int x1, int x2) |
|---|
| 57 | { |
|---|
| 58 | return x1+x2; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | int operator()(int x1, int x2) const |
|---|
| 62 | { |
|---|
| 63 | return -(x1+x2); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | int operator()(int x1, int x2, int x3) |
|---|
| 67 | { |
|---|
| 68 | return x1+x2+x3; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | int operator()(int x1, int x2, int x3) const |
|---|
| 72 | { |
|---|
| 73 | return -(x1+x2+x3); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | int operator()(int x1, int x2, int x3, int x4) |
|---|
| 77 | { |
|---|
| 78 | return x1+x2+x3+x4; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | int operator()(int x1, int x2, int x3, int x4) const |
|---|
| 82 | { |
|---|
| 83 | return -(x1+x2+x3+x4); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | int operator()(int x1, int x2, int x3, int x4, int x5) |
|---|
| 87 | { |
|---|
| 88 | return x1+x2+x3+x4+x5; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | int operator()(int x1, int x2, int x3, int x4, int x5) const |
|---|
| 92 | { |
|---|
| 93 | return -(x1+x2+x3+x4+x5); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6) |
|---|
| 97 | { |
|---|
| 98 | return x1+x2+x3+x4+x5+x6; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6) const |
|---|
| 102 | { |
|---|
| 103 | return -(x1+x2+x3+x4+x5+x6); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) |
|---|
| 107 | { |
|---|
| 108 | return x1+x2+x3+x4+x5+x6+x7; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) const |
|---|
| 112 | { |
|---|
| 113 | return -(x1+x2+x3+x4+x5+x6+x7); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) |
|---|
| 117 | { |
|---|
| 118 | return x1+x2+x3+x4+x5+x6+x7+x8; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) const |
|---|
| 122 | { |
|---|
| 123 | return -(x1+x2+x3+x4+x5+x6+x7+x8); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) |
|---|
| 127 | { |
|---|
| 128 | return x1+x2+x3+x4+x5+x6+x7+x8+x9; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const |
|---|
| 132 | { |
|---|
| 133 | return -(x1+x2+x3+x4+x5+x6+x7+x8+x9); |
|---|
| 134 | } |
|---|
| 135 | }; |
|---|
| 136 | |
|---|
| 137 | template<class F> void test(F f, int r) |
|---|
| 138 | { |
|---|
| 139 | F const & cf = f; |
|---|
| 140 | BOOST_TEST( cf() == -r ); |
|---|
| 141 | BOOST_TEST( f() == r ); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | int main() |
|---|
| 145 | { |
|---|
| 146 | test( boost::bind<int>( X() ), 17041 ); |
|---|
| 147 | test( boost::bind<int>( X(), 1 ), 1 ); |
|---|
| 148 | test( boost::bind<int>( X(), 1, 2 ), 1+2 ); |
|---|
| 149 | test( boost::bind<int>( X(), 1, 2, 3 ), 1+2+3 ); |
|---|
| 150 | test( boost::bind<int>( X(), 1, 2, 3, 4 ), 1+2+3+4 ); |
|---|
| 151 | test( boost::bind<int>( X(), 1, 2, 3, 4, 5 ), 1+2+3+4+5 ); |
|---|
| 152 | test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6 ), 1+2+3+4+5+6 ); |
|---|
| 153 | test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7 ), 1+2+3+4+5+6+7 ); |
|---|
| 154 | test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 1+2+3+4+5+6+7+8 ); |
|---|
| 155 | test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 1+2+3+4+5+6+7+8+9 ); |
|---|
| 156 | |
|---|
| 157 | return boost::report_errors(); |
|---|
| 158 | } |
|---|