| 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_mf2_test.cpp - test for member functions w/ the type<> syntax |
| 12 | // |
| 13 | // Copyright (c) 2005, 2008 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 | mutable unsigned int hash; |
| 28 | |
| 29 | X(): hash(0) {} |
| 30 | |
| 31 | int f0() { f1(a1: 17); return 0; } |
| 32 | int g0() const { g1(a1: 17); return 0; } |
| 33 | |
| 34 | int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; } |
| 35 | int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; } |
| 36 | |
| 37 | int f2(int a1, int a2) { f1(a1); f1(a1: a2); return 0; } |
| 38 | int g2(int a1, int a2) const { g1(a1); g1(a1: a2); return 0; } |
| 39 | |
| 40 | int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a1: a3); return 0; } |
| 41 | int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a1: a3); return 0; } |
| 42 | |
| 43 | int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a1: a4); return 0; } |
| 44 | int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a1: a4); return 0; } |
| 45 | |
| 46 | int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a1: a5); return 0; } |
| 47 | int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a1: a5); return 0; } |
| 48 | |
| 49 | int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a1: a6); return 0; } |
| 50 | int g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a1: a6); return 0; } |
| 51 | |
| 52 | int f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a1: a7); return 0; } |
| 53 | int g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a1: a7); return 0; } |
| 54 | |
| 55 | int f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a1: a8); return 0; } |
| 56 | int g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a1: a8); return 0; } |
| 57 | }; |
| 58 | |
| 59 | void member_function_test() |
| 60 | { |
| 61 | using namespace boost; |
| 62 | |
| 63 | X x; |
| 64 | |
| 65 | // 0 |
| 66 | |
| 67 | bind( type<void>(), f: &X::f0, a1: &x )(); |
| 68 | bind( type<void>(), f: &X::f0, a1: ref(t&: x) )(); |
| 69 | |
| 70 | bind( type<void>(), f: &X::g0, a1: &x )(); |
| 71 | bind( type<void>(), f: &X::g0, a1: x )(); |
| 72 | bind( type<void>(), f: &X::g0, a1: ref(t&: x) )(); |
| 73 | |
| 74 | // 1 |
| 75 | |
| 76 | bind( type<void>(), f: &X::f1, a1: &x, a2: 1 )(); |
| 77 | bind( type<void>(), f: &X::f1, a1: ref(t&: x), a2: 1 )(); |
| 78 | |
| 79 | bind( type<void>(), f: &X::g1, a1: &x, a2: 1 )(); |
| 80 | bind( type<void>(), f: &X::g1, a1: x, a2: 1 )(); |
| 81 | bind( type<void>(), f: &X::g1, a1: ref(t&: x), a2: 1 )(); |
| 82 | |
| 83 | // 2 |
| 84 | |
| 85 | bind( type<void>(), f: &X::f2, a1: &x, a2: 1, a3: 2 )(); |
| 86 | bind( type<void>(), f: &X::f2, a1: ref(t&: x), a2: 1, a3: 2 )(); |
| 87 | |
| 88 | bind( type<void>(), f: &X::g2, a1: &x, a2: 1, a3: 2 )(); |
| 89 | bind( type<void>(), f: &X::g2, a1: x, a2: 1, a3: 2 )(); |
| 90 | bind( type<void>(), f: &X::g2, a1: ref(t&: x), a2: 1, a3: 2 )(); |
| 91 | |
| 92 | // 3 |
| 93 | |
| 94 | bind( type<void>(), f: &X::f3, a1: &x, a2: 1, a3: 2, a4: 3 )(); |
| 95 | bind( type<void>(), f: &X::f3, a1: ref(t&: x), a2: 1, a3: 2, a4: 3 )(); |
| 96 | |
| 97 | bind( type<void>(), f: &X::g3, a1: &x, a2: 1, a3: 2, a4: 3 )(); |
| 98 | bind( type<void>(), f: &X::g3, a1: x, a2: 1, a3: 2, a4: 3 )(); |
| 99 | bind( type<void>(), f: &X::g3, a1: ref(t&: x), a2: 1, a3: 2, a4: 3 )(); |
| 100 | |
| 101 | // 4 |
| 102 | |
| 103 | bind( type<void>(), f: &X::f4, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4 )(); |
| 104 | bind( type<void>(), f: &X::f4, a1: ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4 )(); |
| 105 | |
| 106 | bind( type<void>(), f: &X::g4, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4 )(); |
| 107 | bind( type<void>(), f: &X::g4, a1: x, a2: 1, a3: 2, a4: 3, a5: 4 )(); |
| 108 | bind( type<void>(), f: &X::g4, a1: ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4 )(); |
| 109 | |
| 110 | // 5 |
| 111 | |
| 112 | bind( type<void>(), f: &X::f5, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5 )(); |
| 113 | bind( type<void>(), f: &X::f5, a1: ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5 )(); |
| 114 | |
| 115 | bind( type<void>(), f: &X::g5, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5 )(); |
| 116 | bind( type<void>(), f: &X::g5, a1: x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5 )(); |
| 117 | bind( type<void>(), f: &X::g5, a1: ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5 )(); |
| 118 | |
| 119 | // 6 |
| 120 | |
| 121 | bind( type<void>(), f: &X::f6, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6 )(); |
| 122 | bind( type<void>(), f: &X::f6, a1: ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6 )(); |
| 123 | |
| 124 | bind( type<void>(), f: &X::g6, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6 )(); |
| 125 | bind( type<void>(), f: &X::g6, a1: x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6 )(); |
| 126 | bind( type<void>(), f: &X::g6, a1: ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6 )(); |
| 127 | |
| 128 | // 7 |
| 129 | |
| 130 | bind( type<void>(), f: &X::f7, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7)(); |
| 131 | bind( type<void>(), f: &X::f7, a1: ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7)(); |
| 132 | |
| 133 | bind( type<void>(), f: &X::g7, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7)(); |
| 134 | bind( type<void>(), f: &X::g7, a1: x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7)(); |
| 135 | bind( type<void>(), f: &X::g7, a1: ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7)(); |
| 136 | |
| 137 | // 8 |
| 138 | |
| 139 | bind( type<void>(), f: &X::f8, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7, a9: 8 )(); |
| 140 | bind( type<void>(), f: &X::f8, a1: ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7, a9: 8 )(); |
| 141 | |
| 142 | bind( type<void>(), f: &X::g8, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7, a9: 8 )(); |
| 143 | bind( type<void>(), f: &X::g8, a1: x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7, a9: 8 )(); |
| 144 | bind( type<void>(), f: &X::g8, a1: ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7, a9: 8 )(); |
| 145 | |
| 146 | BOOST_TEST( x.hash == 23558 ); |
| 147 | } |
| 148 | |
| 149 | int main() |
| 150 | { |
| 151 | member_function_test(); |
| 152 | return boost::report_errors(); |
| 153 | } |
| 154 | |