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
22 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
23 #pragma warning(push, 3)
24 #endif
25
26 #include <iostream>
27
28 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
29 #pragma warning(pop)
30 #endif
31
32 #include <boost/detail/lightweight_test.hpp>
33
34 struct X
35 {
36 int m;
37 };
38
f(int v)39 X f( int v )
40 {
41 X r = { v };
42 return r;
43 }
44
main()45 int main()
46 {
47 using boost::phoenix::bind;
48 using boost::phoenix::ref;
49 using boost::phoenix::placeholders::_1;
50
51 X x = { 17041 };
52 X * px = &x;
53
54 BOOST_TEST( bind( &X::m, _1 )( x ) == 17041 );
55 BOOST_TEST( bind( &X::m, _1 )( px ) == 17041 );
56
57 BOOST_TEST( bind( &X::m, x )() == 17041 );
58 BOOST_TEST( bind( &X::m, px )() == 17041 );
59 BOOST_TEST( bind( &X::m, ref(x) )() == 17041 );
60
61
62 X const cx = x;
63 X const * pcx = &cx;
64
65 BOOST_TEST( bind( &X::m, _1 )( cx ) == 17041 );
66 BOOST_TEST( bind( &X::m, _1 )( pcx ) == 17041 );
67
68 BOOST_TEST( bind( &X::m, cx )() == 17041 );
69 BOOST_TEST( bind( &X::m, pcx )() == 17041 );
70 BOOST_TEST( bind( &X::m, ref(cx) )() == 17041 );
71
72 int const v = 42;
73 // Change bind_dm_test.cpp to bind to _1 twice.
74 BOOST_TEST( bind( &X::m, _1)( bind( f, _1 )( v ) ) == v );
75
76 return boost::report_errors();
77 }
78