| 1 | #include <boost/config.hpp> |
| 2 | |
| 3 | #if defined(BOOST_MSVC) |
| 4 | #pragma warning(disable: 4786) // identifier truncated in debug info |
| 5 | #pragma warning(disable: 4710) // function not inlined |
| 6 | #pragma warning(disable: 4711) // function selected for automatic inline expansion |
| 7 | #pragma warning(disable: 4514) // unreferenced inline removed |
| 8 | #endif |
| 9 | |
| 10 | // |
| 11 | // bind_dm_test.cpp - data members |
| 12 | // |
| 13 | // Copyright (c) 2005 Peter Dimov |
| 14 | // |
| 15 | // Distributed under the Boost Software License, Version 1.0. (See |
| 16 | // accompanying file LICENSE_1_0.txt or copy at |
| 17 | // http://www.boost.org/LICENSE_1_0.txt) |
| 18 | // |
| 19 | |
| 20 | #include <boost/bind/bind.hpp> |
| 21 | #include <boost/core/lightweight_test.hpp> |
| 22 | |
| 23 | using namespace boost::placeholders; |
| 24 | |
| 25 | // |
| 26 | |
| 27 | struct X |
| 28 | { |
| 29 | int m; |
| 30 | }; |
| 31 | |
| 32 | X f( int v ) |
| 33 | { |
| 34 | X r = { .m: v }; |
| 35 | return r; |
| 36 | } |
| 37 | |
| 38 | int main() |
| 39 | { |
| 40 | X x = { .m: 17041 }; |
| 41 | X * px = &x; |
| 42 | |
| 43 | BOOST_TEST( boost::bind( &X::m, _1 )( x ) == 17041 ); |
| 44 | BOOST_TEST( boost::bind( &X::m, _1 )( px ) == 17041 ); |
| 45 | |
| 46 | BOOST_TEST( boost::bind( &X::m, x )() == 17041 ); |
| 47 | BOOST_TEST( boost::bind( &X::m, px )() == 17041 ); |
| 48 | BOOST_TEST( boost::bind( &X::m, boost::ref(x) )() == 17041 ); |
| 49 | |
| 50 | |
| 51 | X const cx = x; |
| 52 | X const * pcx = &cx; |
| 53 | |
| 54 | BOOST_TEST( boost::bind( &X::m, _1 )( cx ) == 17041 ); |
| 55 | BOOST_TEST( boost::bind( &X::m, _1 )( pcx ) == 17041 ); |
| 56 | |
| 57 | BOOST_TEST( boost::bind( &X::m, cx )() == 17041 ); |
| 58 | BOOST_TEST( boost::bind( &X::m, pcx )() == 17041 ); |
| 59 | BOOST_TEST( boost::bind( &X::m, boost::ref(cx) )() == 17041 ); |
| 60 | |
| 61 | int const v = 42; |
| 62 | |
| 63 | BOOST_TEST( boost::bind( &X::m, boost::bind( f, _1 ) )( v ) == v ); |
| 64 | |
| 65 | return boost::report_errors(); |
| 66 | } |
| 67 | |