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_dm2_test.cpp - data members, advanced uses
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#include <string>
23
24using namespace boost::placeholders;
25
26//
27
28struct X
29{
30 int m;
31};
32
33struct Y
34{
35 char m[ 64 ];
36};
37
38int main()
39{
40 X x = { .m: 0 };
41 X * px = &x;
42
43 boost::bind< int& >( f: &X::m, a1: _1 )( px ) = 42;
44
45 BOOST_TEST( x.m == 42 );
46
47 boost::bind< int& >( f: &X::m, a1: boost::ref(t&: x) )() = 17041;
48
49 BOOST_TEST( x.m == 17041 );
50
51 X const * pcx = &x;
52
53 BOOST_TEST( boost::bind< long >( &X::m, _1 )( pcx ) == 17041L );
54 BOOST_TEST( boost::bind< long >( &X::m, pcx )() == 17041L );
55
56 Y y = { .m: "test" };
57 std::string v( "test" );
58
59 BOOST_TEST( boost::bind< char const* >( &Y::m, &y )() == v );
60 BOOST_TEST( boost::bind< std::string >( &Y::m, &y )() == v );
61
62 return boost::report_errors();
63}
64

source code of boost/libs/bind/test/bind_dm2_test.cpp