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