]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/boost_bind_compatibility/bind_interoperation_test.cpp
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
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 ==============================================================================*/
11 #include <boost/config.hpp>
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
20 #include <boost/function.hpp>
21 #include <boost/bind.hpp>
22 #include <boost/phoenix/core.hpp>
23 #include <boost/phoenix/bind.hpp>
24 #include <boost/detail/lightweight_test.hpp>
26 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
27 #pragma warning(push, 3)
31 #include <boost/function.hpp>
33 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
42 int f2( int x
, int y
)
53 int f0() { n
+= f1(17); return n
; }
54 int g0() const { n
+= g1(17); return n
; }
57 int f1(int a1
) { return a1
; }
58 int g1(int a1
) const { return a1
; }
66 namespace phx
= boost::phoenix
;
67 using phx::placeholders::arg1
;
68 using phx::placeholders::arg2
;
69 using boost::phoenix::ref
;
76 BOOST_TEST( boost::bind( &Y::m
, _1
)( y
) == 17041 );
77 BOOST_TEST( boost::bind( &Y::m
, _1
)( py
) == 17041 );
79 BOOST_TEST( phx::bind( &Y::m
, _1
)( y
) == 17041 );
80 BOOST_TEST( phx::bind( &Y::m
, _1
)( py
) == 17041 );
82 BOOST_TEST( phx::bind( &Y::m
, arg1
)( y
) == 17041 );
83 BOOST_TEST( phx::bind( &Y::m
, arg1
)( py
) == 17041 );
85 BOOST_TEST( boost::bind( &Y::m
, y
)() == 17041 );
86 BOOST_TEST( boost::bind( &Y::m
, py
)() == 17041 );
87 //BOOST_TEST( boost::bind( &Y::m, ref(y) )() == 17041 );
89 BOOST_TEST( phx::bind( &Y::m
, y
)() == 17041 );
90 BOOST_TEST( phx::bind( &Y::m
, py
)() == 17041 );
91 BOOST_TEST( phx::bind( &Y::m
, ref(y
) )() == 17041 );
96 void member_function_test()
103 BOOST_TEST(boost::bind(&X::f0
, &x
)() == 17);
104 //boost::bind(&X::f0, ref(x) )(); boost::bind does not work with phx::ref.
106 BOOST_TEST(boost::bind(&X::g0
, &x
)() == 34);
107 BOOST_TEST(boost::bind(&X::g0
, x
)() == 51);
108 //boost::bind(&X::g0, ref(x) )();
110 BOOST_TEST(phx::bind(&X::f0
, &x
)() == 51);
111 BOOST_TEST(phx::bind(&X::f0
, ref(x
) )() == 68);
113 BOOST_TEST(phx::bind(&X::g0
, &x
)() == 85);
114 BOOST_TEST(phx::bind(&X::g0
, x
)() == 102);
115 BOOST_TEST(phx::bind(&X::g0
, ref(x
) )() == 102);
123 boost::function
<int (int)> fun1_f1(boost::bind ( &f1
, _1
) );
124 boost::function
<int (int)> fun2_f1( phx::bind ( &f1
, _1
) );
125 boost::function
<int (int)> fun3_f1( phx::bind ( &f1
, arg1
) );
127 BOOST_TEST( fun1_f1(1) == 1 );
128 BOOST_TEST( fun2_f1(2) == 2 );
129 BOOST_TEST( fun3_f1(3) == 3 );
131 boost::function
<int (int, int)> fun1_f2(boost::bind ( &f2
, _1
, _2
) );
132 boost::function
<int (int, int)> fun2_f2( phx::bind ( &f2
, _1
, _2
) );
133 boost::function
<int (int, int)> fun3_f2( phx::bind ( &f2
, arg1
, arg2
) );
135 BOOST_TEST( fun1_f2(1,2) == 3 );
136 BOOST_TEST( fun2_f2(2,3) == 5 );
137 BOOST_TEST( fun3_f2(3,4) == 7 );
139 member_function_test();
141 return boost::report_errors();