1/*==============================================================================
2 Copyright (c) 2005 Peter Dimov
3 Copyright (c) 2005-2010 Joel de Guzman
4 Copyright (c) 2010 Thomas Heller
5
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8==============================================================================*/
9
10#include <boost/config.hpp>
11
12#if defined(BOOST_MSVC)
13#pragma warning(disable: 4786) // identifier truncated in debug info
14#pragma warning(disable: 4710) // function not inlined
15#pragma warning(disable: 4711) // function selected for automatic inline expansion
16#pragma warning(disable: 4514) // unreferenced inline removed
17#endif
18
19#include <boost/phoenix/core.hpp>
20#include <boost/phoenix/bind.hpp>
21#include <boost/detail/lightweight_test.hpp>
22
23#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
24#pragma warning(push, 3)
25#endif
26
27#include <iostream>
28#include <boost/function.hpp>
29
30#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
31#pragma warning(pop)
32#endif
33
34int f( int x )
35{
36 return x;
37}
38
39int g( int x )
40{
41 return x + 1;
42}
43
44int main()
45{
46 using boost::phoenix::bind;
47
48 boost::function0<int> fn;
49
50 BOOST_TEST( !fn.contains( bind( f, 1 ) ) );
51 BOOST_TEST( !fn.contains( bind( f, 2 ) ) );
52 BOOST_TEST( !fn.contains( bind( g, 1 ) ) );
53
54 fn = bind( f, a: 1 );
55
56 BOOST_TEST( fn() == 1 );
57
58 BOOST_TEST( fn.contains( bind( f, 1 ) ) );
59 BOOST_TEST( !fn.contains( bind( f, 2 ) ) );
60 BOOST_TEST( !fn.contains( bind( g, 1 ) ) );
61
62 fn = bind( f, a: 2 );
63
64 BOOST_TEST( fn() == 2 );
65
66 BOOST_TEST( !fn.contains( bind( f, 1 ) ) );
67 BOOST_TEST( fn.contains( bind( f, 2 ) ) );
68 BOOST_TEST( !fn.contains( bind( g, 1 ) ) );
69
70 fn = bind( f: g, a: 1 );
71
72 BOOST_TEST( fn() == 2 );
73
74 BOOST_TEST( !fn.contains( bind( f, 1 ) ) );
75 BOOST_TEST( !fn.contains( bind( f, 2 ) ) );
76 BOOST_TEST( fn.contains( bind( g, 1 ) ) );
77
78 return boost::report_errors();
79}
80

source code of boost/libs/phoenix/test/boost_bind_compatibility/bind_function_test.cpp