| 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 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
|---|
| 21 | #pragma warning(push, 3) |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | #include <iostream> |
|---|
| 25 | #include <boost/function.hpp> |
|---|
| 26 | |
|---|
| 27 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) |
|---|
| 28 | #pragma warning(pop) |
|---|
| 29 | #endif |
|---|
| 30 | |
|---|
| 31 | #include <boost/bind.hpp> |
|---|
| 32 | #include <boost/detail/lightweight_test.hpp> |
|---|
| 33 | |
|---|
| 34 | int f( int x ) |
|---|
| 35 | { |
|---|
| 36 | return x; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | int g( int x ) |
|---|
| 40 | { |
|---|
| 41 | return x + 1; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | int main() |
|---|
| 45 | { |
|---|
| 46 | boost::function0<int> fn; |
|---|
| 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, 1 ); |
|---|
| 53 | |
|---|
| 54 | BOOST_TEST( fn() == 1 ); |
|---|
| 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, 2 ); |
|---|
| 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 | fn = boost::bind( g, 1 ); |
|---|
| 69 | |
|---|
| 70 | BOOST_TEST( fn() == 2 ); |
|---|
| 71 | |
|---|
| 72 | BOOST_TEST( !fn.contains( boost::bind( f, 1 ) ) ); |
|---|
| 73 | BOOST_TEST( !fn.contains( boost::bind( f, 2 ) ) ); |
|---|
| 74 | BOOST_TEST( fn.contains( boost::bind( g, 1 ) ) ); |
|---|
| 75 | |
|---|
| 76 | return boost::report_errors(); |
|---|
| 77 | } |
|---|