1/*=============================================================================
2 Copyright (c) 2001-2007 Joel de Guzman
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6==============================================================================*/
7#include <iostream>
8#include <cmath>
9#include <boost/noncopyable.hpp>
10#include <boost/detail/lightweight_test.hpp>
11#include <boost/phoenix/core.hpp>
12#include <boost/phoenix/bind.hpp>
13
14namespace test
15{
16 struct x //: boost::noncopyable // test non-copyable (hold this by reference)
17 {
18 int m;
19 };
20
21 struct xx {
22 int m;
23 };
24}
25
26template <typename T, typename F>
27void
28write_test(F f)
29{
30 using boost::phoenix::arg_names::arg1;
31 using boost::phoenix::bind;
32
33 T x_;
34
35 bind(&T::m, f(x_))() = 122;
36 BOOST_TEST(x_.m == 122);
37 bind(&T::m, arg1)(f(x_)) = 123;
38 BOOST_TEST(x_.m == 123);
39}
40
41template <typename T, typename F>
42void
43read_test(F f)
44{
45 using boost::phoenix::arg_names::arg1;
46 using boost::phoenix::bind;
47
48 T x_;
49 x_.m = 123;
50
51 BOOST_TEST(bind(&T::m, f(x_))() == 123);
52 BOOST_TEST(bind(&T::m, arg1)(f(x_)) == 123);
53}
54
55struct identity
56{
57 template <typename T>
58 T&
59 operator()(T& t) const
60 {
61 return t;
62 }
63};
64
65struct constify
66{
67 template <typename T>
68 T const&
69 operator()(T const& t) const
70 {
71 return t;
72 }
73};
74
75struct add_pointer
76{
77 template <typename T>
78 T* /*const*/
79 operator()(T& t) const
80 {
81 return &t;
82 }
83};
84
85struct add_const_pointer
86{
87 template <typename T>
88 const T* /*const*/
89 operator()(T const& t) const
90 {
91 return &t;
92 }
93};
94
95int
96main()
97{
98 write_test<test::x>(f: add_pointer());
99 write_test<test::xx>(f: add_pointer());
100
101 read_test<test::x>(f: identity());
102 read_test<test::x>(f: constify());
103 read_test<test::x>(f: add_pointer());
104 read_test<test::x>(f: add_const_pointer());
105 read_test<test::xx>(f: identity());
106 read_test<test::xx>(f: constify());
107 read_test<test::xx>(f: add_pointer());
108 read_test<test::xx>(f: add_const_pointer());
109
110 return boost::report_errors();
111}
112

source code of boost/libs/phoenix/test/bind/bind_member_variable_tests.cpp