| 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.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 | |
|---|
| 39 | X f( int v ) |
|---|
| 40 | { |
|---|
| 41 | X r = { v }; |
|---|
| 42 | return r; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | int main() |
|---|
| 46 | { |
|---|
| 47 | X x = { 17041 }; |
|---|
| 48 | X * px = &x; |
|---|
| 49 | |
|---|
| 50 | BOOST_TEST( boost::bind( &X::m, _1 )( x ) == 17041 ); |
|---|
| 51 | BOOST_TEST( boost::bind( &X::m, _1 )( px ) == 17041 ); |
|---|
| 52 | |
|---|
| 53 | BOOST_TEST( boost::bind( &X::m, x )() == 17041 ); |
|---|
| 54 | BOOST_TEST( boost::bind( &X::m, px )() == 17041 ); |
|---|
| 55 | BOOST_TEST( boost::bind( &X::m, boost::ref(x) )() == 17041 ); |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | X const cx = x; |
|---|
| 59 | X const * pcx = &cx; |
|---|
| 60 | |
|---|
| 61 | BOOST_TEST( boost::bind( &X::m, _1 )( cx ) == 17041 ); |
|---|
| 62 | BOOST_TEST( boost::bind( &X::m, _1 )( pcx ) == 17041 ); |
|---|
| 63 | |
|---|
| 64 | BOOST_TEST( boost::bind( &X::m, cx )() == 17041 ); |
|---|
| 65 | BOOST_TEST( boost::bind( &X::m, pcx )() == 17041 ); |
|---|
| 66 | BOOST_TEST( boost::bind( &X::m, boost::ref(cx) )() == 17041 ); |
|---|
| 67 | |
|---|
| 68 | int const v = 42; |
|---|
| 69 | |
|---|
| 70 | BOOST_TEST( boost::bind( &X::m, boost::bind( f, _1 ) )( v ) == v ); |
|---|
| 71 | |
|---|
| 72 | return boost::report_errors(); |
|---|
| 73 | } |
|---|