| 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_function_test.cpp - function<> |
| 12 | // |
| 13 | // Copyright (c) 2005 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/function.hpp> |
| 22 | #include <boost/core/lightweight_test.hpp> |
| 23 | |
| 24 | // |
| 25 | |
| 26 | int f( int x ) |
| 27 | { |
| 28 | return x; |
| 29 | } |
| 30 | |
| 31 | int g( int x ) |
| 32 | { |
| 33 | return x + 1; |
| 34 | } |
| 35 | |
| 36 | int main() |
| 37 | { |
| 38 | boost::function0<int> fn; |
| 39 | |
| 40 | BOOST_TEST( !fn.contains( boost::bind( f, 1 ) ) ); |
| 41 | BOOST_TEST( !fn.contains( boost::bind( f, 2 ) ) ); |
| 42 | BOOST_TEST( !fn.contains( boost::bind( g, 1 ) ) ); |
| 43 | |
| 44 | fn = boost::bind( f, a1: 1 ); |
| 45 | |
| 46 | BOOST_TEST( fn() == 1 ); |
| 47 | |
| 48 | BOOST_TEST( fn.contains( boost::bind( f, 1 ) ) ); |
| 49 | BOOST_TEST( !fn.contains( boost::bind( f, 2 ) ) ); |
| 50 | BOOST_TEST( !fn.contains( boost::bind( g, 1 ) ) ); |
| 51 | |
| 52 | fn = boost::bind( f, a1: 2 ); |
| 53 | |
| 54 | BOOST_TEST( fn() == 2 ); |
| 55 | |
| 56 | BOOST_TEST( !fn.contains( boost::bind( f, 1 ) ) ); |
| 57 | BOOST_TEST( fn.contains( boost::bind( f, 2 ) ) ); |
| 58 | BOOST_TEST( !fn.contains( boost::bind( g, 1 ) ) ); |
| 59 | |
| 60 | fn = boost::bind( f: g, a1: 1 ); |
| 61 | |
| 62 | BOOST_TEST( fn() == 2 ); |
| 63 | |
| 64 | BOOST_TEST( !fn.contains( boost::bind( f, 1 ) ) ); |
| 65 | BOOST_TEST( !fn.contains( boost::bind( f, 2 ) ) ); |
| 66 | BOOST_TEST( fn.contains( boost::bind( g, 1 ) ) ); |
| 67 | |
| 68 | return boost::report_errors(); |
| 69 | } |
| 70 | |