]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_erasure/test/test_member.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / type_erasure / test / test_member.cpp
1 // Boost.TypeErasure library
2 //
3 // Copyright 2012 Steven Watanabe
4 //
5 // Distributed under the Boost Software License Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // $Id$
10
11 #include <boost/type_erasure/any.hpp>
12 #include <boost/type_erasure/builtin.hpp>
13 #include <boost/type_erasure/member.hpp>
14 #include <boost/mpl/vector.hpp>
15
16 #define BOOST_TEST_MAIN
17 #include <boost/test/unit_test.hpp>
18
19 using namespace boost::type_erasure;
20
21 BOOST_TYPE_ERASURE_MEMBER((ns)(ns2)(has_fun), fun, 0)
22
23 struct model {
24 explicit model(int v) : val(v) {}
25 int f1() { return val; }
26 int f1(int i) { return val + i; }
27 int val;
28 };
29
30 BOOST_TYPE_ERASURE_MEMBER((global_has_f1_0), f1, 0)
31
32 BOOST_AUTO_TEST_CASE(test_global_has_f1_0) {
33 typedef ::boost::mpl::vector<
34 global_has_f1_0<int()>,
35 copy_constructible<> > concept_type;
36 model m(10);
37 any<concept_type> x(m);
38 BOOST_CHECK_EQUAL(x.f1(), 10);
39 }
40
41 BOOST_AUTO_TEST_CASE(test_global_has_f1_0_ref) {
42 typedef ::boost::mpl::vector<
43 global_has_f1_0<int()>,
44 copy_constructible<> > concept_type;
45 model m(10);
46 const any<concept_type, _self&> x(m);
47 BOOST_CHECK_EQUAL(x.f1(), 10);
48 }
49
50 BOOST_TYPE_ERASURE_MEMBER((ns1)(ns2)(ns_has_f1_0), f1, 0)
51
52 BOOST_AUTO_TEST_CASE(test_ns_has_f1_0) {
53 typedef ::boost::mpl::vector<
54 ns1::ns2::ns_has_f1_0<int()>,
55 copy_constructible<> > concept_type;
56 model m(10);
57 any<concept_type> x(m);
58 BOOST_CHECK_EQUAL(x.f1(), 10);
59 }
60
61 struct model_const {
62 explicit model_const(int v) : val(v) {}
63 int f1() const { return val; }
64 int f1(int i) const { return val + i; }
65 int val;
66 };
67
68 BOOST_AUTO_TEST_CASE(test_global_has_f1_0_const) {
69 typedef ::boost::mpl::vector<
70 ns1::ns2::ns_has_f1_0<int(), const _self>,
71 copy_constructible<> > concept_type;
72 model_const m(10);
73 any<concept_type> x(m);
74 BOOST_CHECK_EQUAL(x.f1(), 10);
75 }
76
77 BOOST_AUTO_TEST_CASE(test_global_has_f1_0_const_ref) {
78 typedef ::boost::mpl::vector<
79 ns1::ns2::ns_has_f1_0<int(), const _self>,
80 copy_constructible<> > concept_type;
81 model_const m(10);
82 const any<concept_type, _self&> x(m);
83 BOOST_CHECK_EQUAL(x.f1(), 10);
84 }
85
86 BOOST_AUTO_TEST_CASE(test_global_has_f1_0_const_cref) {
87 typedef ::boost::mpl::vector<
88 ns1::ns2::ns_has_f1_0<int(), const _self>,
89 copy_constructible<> > concept_type;
90 model_const m(10);
91 const any<concept_type, const _self&> x(m);
92 BOOST_CHECK_EQUAL(x.f1(), 10);
93 }
94
95 BOOST_AUTO_TEST_CASE(test_global_has_f1_0_void) {
96 typedef ::boost::mpl::vector<
97 global_has_f1_0<void()>,
98 copy_constructible<> > concept_type;
99 model m(10);
100 any<concept_type> x(m);
101 x.f1();
102 }
103
104 BOOST_TYPE_ERASURE_MEMBER((global_has_f1_1), f1, 1)
105
106 BOOST_AUTO_TEST_CASE(test_global_has_f1_overload) {
107 typedef ::boost::mpl::vector<
108 global_has_f1_0<int()>,
109 global_has_f1_1<int(int)>,
110 copy_constructible<> > concept_type;
111 model m(10);
112 any<concept_type> x(m);
113 BOOST_CHECK_EQUAL(x.f1(), 10);
114 BOOST_CHECK_EQUAL(x.f1(5), 15);
115 }
116
117 BOOST_AUTO_TEST_CASE(test_global_has_f1_overload_const) {
118 typedef ::boost::mpl::vector<
119 global_has_f1_0<int(), const _self>,
120 global_has_f1_1<int(int), const _self>,
121 copy_constructible<> > concept_type;
122 model_const m(10);
123 any<concept_type> x(m);
124 BOOST_CHECK_EQUAL(x.f1(), 10);
125 BOOST_CHECK_EQUAL(x.f1(5), 15);
126 }
127
128 struct model_overload_const_non_const {
129 int f1() { return 1; }
130 int f1() const { return 2; }
131 };
132
133 BOOST_AUTO_TEST_CASE(test_global_has_f1_overload_const_non_const) {
134 typedef ::boost::mpl::vector<
135 global_has_f1_0<int(), _self>,
136 global_has_f1_0<int(), const _self>,
137 copy_constructible<> > concept_type;
138 model_overload_const_non_const m;
139 any<concept_type> x1(m);
140 BOOST_CHECK_EQUAL(x1.f1(), 1);
141 const any<concept_type> x2(m);
142 BOOST_CHECK_EQUAL(x2.f1(), 2);
143 }
144
145 BOOST_AUTO_TEST_CASE(test_global_has_f1_overload_const_non_const_ref) {
146 typedef ::boost::mpl::vector<
147 global_has_f1_0<int(), const _self>, // FIXME: This is order sensitive
148 global_has_f1_0<int(), _self>,
149 copy_constructible<> > concept_type;
150 model_overload_const_non_const m;
151 any<concept_type, _self&> x1(m);
152 BOOST_CHECK_EQUAL(x1.f1(), 1);
153 const any<concept_type, _self&> x2(m);
154 BOOST_CHECK_EQUAL(x2.f1(), 1);
155 }
156
157 BOOST_AUTO_TEST_CASE(test_global_has_f1_overload_const_non_const_cref) {
158 typedef ::boost::mpl::vector<
159 global_has_f1_0<int(), _self>,
160 global_has_f1_0<int(), const _self>,
161 copy_constructible<> > concept_type;
162 model_overload_const_non_const m;
163 any<concept_type, const _self&> x1(m);
164 BOOST_CHECK_EQUAL(x1.f1(), 2);
165 const any<concept_type, const _self&> x2(m);
166 BOOST_CHECK_EQUAL(x2.f1(), 2);
167 }
168
169 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
170
171 BOOST_AUTO_TEST_CASE(test_global_has_f1_rv) {
172 typedef ::boost::mpl::vector<
173 global_has_f1_1<int(int&&)>,
174 copy_constructible<> > concept_type;
175 model m(10);
176 any<concept_type> x(m);
177 BOOST_CHECK_EQUAL(x.f1(5), 15);
178 }
179
180 BOOST_AUTO_TEST_CASE(test_global_has_f1_rv_const) {
181 typedef ::boost::mpl::vector<
182 global_has_f1_1<int(int&&), const _self>,
183 copy_constructible<> > concept_type;
184 model_const m(10);
185 const any<concept_type> x(m);
186 BOOST_CHECK_EQUAL(x.f1(5), 15);
187 }
188
189 #endif
190
191
192 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && \
193 !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
194 !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
195 !defined(BOOST_NO_CXX11_DECLTYPE) && \
196 !BOOST_WORKAROUND(BOOST_MSVC, == 1800)
197
198 namespace ns3 {
199 BOOST_TYPE_ERASURE_MEMBER(f1);
200 }
201
202 BOOST_AUTO_TEST_CASE(test_simple_member_0) {
203 typedef ::boost::mpl::vector<
204 ns3::has_f1<int()>,
205 copy_constructible<> > concept_type;
206 model m(10);
207 any<concept_type> x(m);
208 BOOST_CHECK_EQUAL(x.f1(), 10);
209 }
210
211 BOOST_AUTO_TEST_CASE(test_simple_member_1) {
212 typedef ::boost::mpl::vector<
213 ns3::has_f1<int(int)>,
214 copy_constructible<> > concept_type;
215 model m(10);
216 any<concept_type> x(m);
217 BOOST_CHECK_EQUAL(x.f1(5), 15);
218 }
219
220 namespace ns3 {
221 BOOST_TYPE_ERASURE_MEMBER(has_f1_ex, f1);
222 }
223
224 BOOST_AUTO_TEST_CASE(test_named_member_1) {
225 typedef ::boost::mpl::vector<
226 ns3::has_f1_ex<int(int)>,
227 copy_constructible<> > concept_type;
228 model m(10);
229 any<concept_type> x(m);
230 BOOST_CHECK_EQUAL(x.f1(5), 15);
231 }
232
233 BOOST_AUTO_TEST_CASE(test_named_member_1_const) {
234 typedef ::boost::mpl::vector<
235 ns3::has_f1_ex<int(int) const>,
236 copy_constructible<> > concept_type;
237 model_const m(10);
238 const any<concept_type> x(m);
239 BOOST_CHECK_EQUAL(x.f1(5), 15);
240 }
241
242 #endif