1 /*==============================================================================
2     Copyright (c) 2005 Peter Dimov
3     Copyright (c) 2005-2010 Joel de Guzman
4     Copyright (c) 2010 Thomas Heller
5     Copyright (c) 2015 John Fletcher
6 
7     Distributed under the Boost Software License, Version 1.0. (See accompanying
8     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 ==============================================================================*/
10 
11 #include <boost/config.hpp>
12 
13 #if defined(BOOST_MSVC)
14 #pragma warning(disable: 4786)  // identifier truncated in debug info
15 #pragma warning(disable: 4710)  // function not inlined
16 #pragma warning(disable: 4711)  // function selected for automatic inline expansion
17 #pragma warning(disable: 4514)  // unreferenced inline removed
18 #endif
19 
20 #include <boost/phoenix/core.hpp>
21 #include <boost/phoenix/bind.hpp>
22 
23 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
24 #pragma warning(push, 3)
25 #endif
26 
27 #include <iostream>
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 
f(int v)40 X f( int v )
41 {
42     X r = { v };
43     return r;
44 }
45 
main()46 int main()
47 {
48     using boost::phoenix::bind;
49     using boost::phoenix::ref;
50     using boost::phoenix::placeholders::_1;
51 
52     X x = { 17041 };
53     X * px = &x;
54 
55     BOOST_TEST( bind( &X::m, _1 )( x ) == 17041 );
56     BOOST_TEST( bind( &X::m, _1 )( px ) == 17041 );
57 
58     BOOST_TEST( bind( &X::m, x )() == 17041 );
59     BOOST_TEST( bind( &X::m, px )() == 17041 );
60     BOOST_TEST( bind( &X::m, ref(x) )() == 17041 );
61 
62 
63     X const cx = x;
64     X const * pcx = &cx;
65 
66     BOOST_TEST( bind( &X::m, _1 )( cx ) == 17041 );
67     BOOST_TEST( bind( &X::m, _1 )( pcx ) == 17041 );
68 
69     BOOST_TEST( bind( &X::m, cx )() == 17041 );
70     BOOST_TEST( bind( &X::m, pcx )() == 17041 );
71     BOOST_TEST( bind( &X::m, ref(cx) )() == 17041 );
72 
73     int const v = 42;
74 
75 // NOTE: The second case does not work with compiler optimization.
76 // This is a bug which has not yet been fixed.
77 // The current test for gcc 4.7.3 does use -O2 but does not
78 // satisfy this first part of the test for some unknown reason.
79 // So this is set to run the first case for all gcc 4.7
80 #if (defined(__OPTIMIZE__) && __OPTIMIZE__) || \
81     defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 40700) && (BOOST_GCC_VERSION < 40800)
82     // Change bind_dm_test.cpp to bind to _1 twice.
83     BOOST_TEST( bind( &X::m, _1)( bind( f, _1 )( v ) ) == v );
84 #else
85     BOOST_TEST( bind( &X::m, bind( f, _1 ) )( v ) == v );
86 #endif
87     return boost::report_errors();
88 }
89