| 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_fnobj2_test.cpp - test for function objects 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 operator()() const { operator()(a1: 17); return 0; } |
| 32 | int operator()(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; } |
| 33 | int operator()(int a1, int a2) const { operator()(a1); operator()(a1: a2); return 0; } |
| 34 | int operator()(int a1, int a2, int a3) const { operator()(a1, a2); operator()(a1: a3); return 0; } |
| 35 | int operator()(int a1, int a2, int a3, int a4) const { operator()(a1, a2, a3); operator()(a1: a4); return 0; } |
| 36 | int operator()(int a1, int a2, int a3, int a4, int a5) const { operator()(a1, a2, a3, a4); operator()(a1: a5); return 0; } |
| 37 | int operator()(int a1, int a2, int a3, int a4, int a5, int a6) const { operator()(a1, a2, a3, a4, a5); operator()(a1: a6); return 0; } |
| 38 | int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { operator()(a1, a2, a3, a4, a5, a6); operator()(a1: a7); return 0; } |
| 39 | int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { operator()(a1, a2, a3, a4, a5, a6, a7); operator()(a1: a8); return 0; } |
| 40 | int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9) const { operator()(a1, a2, a3, a4, a5, a6, a7, a8); operator()(a1: a9); return 0; } |
| 41 | }; |
| 42 | |
| 43 | void function_object_test() |
| 44 | { |
| 45 | using namespace boost; |
| 46 | |
| 47 | X x; |
| 48 | |
| 49 | bind( type<void>(), f: ref(t&: x) )(); |
| 50 | bind( type<void>(), f: ref(t&: x), a: 1 )(); |
| 51 | bind( type<void>(), f: ref(t&: x), a: 1, a: 2 )(); |
| 52 | bind( type<void>(), f: ref(t&: x), a: 1, a: 2, a: 3 )(); |
| 53 | bind( type<void>(), f: ref(t&: x), a: 1, a: 2, a: 3, a: 4 )(); |
| 54 | bind( type<void>(), f: ref(t&: x), a: 1, a: 2, a: 3, a: 4, a: 5 )(); |
| 55 | bind( type<void>(), f: ref(t&: x), a: 1, a: 2, a: 3, a: 4, a: 5, a: 6 )(); |
| 56 | bind( type<void>(), f: ref(t&: x), a: 1, a: 2, a: 3, a: 4, a: 5, a: 6, a: 7)(); |
| 57 | bind( type<void>(), f: ref(t&: x), a: 1, a: 2, a: 3, a: 4, a: 5, a: 6, a: 7, a: 8 )(); |
| 58 | bind( type<void>(), f: ref(t&: x), a: 1, a: 2, a: 3, a: 4, a: 5, a: 6, a: 7, a: 8, a: 9 )(); |
| 59 | |
| 60 | BOOST_TEST( x.hash == 9932 ); |
| 61 | } |
| 62 | |
| 63 | int main() |
| 64 | { |
| 65 | function_object_test(); |
| 66 | return boost::report_errors(); |
| 67 | } |
| 68 | |