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 #include <string>
28 
29 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
30 #pragma warning(pop)
31 #endif
32 
33 #include <boost/detail/lightweight_test.hpp>
34 
35 struct X
36 {
37     int m;
38 };
39 
40 struct Y
41 {
42     char m[ 64 ];
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 = { 0 };
52     X * px = &x;
53 
54     bind( &X::m, _1 )( px ) = 42;
55 
56     BOOST_TEST( x.m == 42 );
57 
58     bind( &X::m, ref(x) )() = 17041;
59 
60     BOOST_TEST( x.m == 17041 );
61 
62     X const * pcx = &x;
63 
64     BOOST_TEST( bind( &X::m, _1 )( pcx ) == 17041L );
65     BOOST_TEST( bind( &X::m, pcx )() == 17041L );
66 
67     Y y = { "test" };
68     std::string v( "test" );
69 
70     BOOST_TEST( bind( &Y::m, &y )() == v );
71     BOOST_TEST( bind( &Y::m, &y )() == v );
72 
73     return boost::report_errors();
74 }
75