]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/sequence/traits.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / traits.hpp
1 /*=============================================================================
2 Copyright (C) 2016 Lee Clagett
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
8 #include <boost/config.hpp>
9 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/fusion/container/list.hpp>
11 #include <boost/fusion/container/vector.hpp>
12 #include <boost/type_traits/add_const.hpp>
13 #include <boost/type_traits/add_reference.hpp>
14 #include <boost/type_traits/integral_constant.hpp>
15 #include <boost/type_traits/is_constructible.hpp>
16 #include <boost/type_traits/is_convertible.hpp>
17 #include <boost/type_traits/remove_const.hpp>
18 #include <boost/type_traits/remove_reference.hpp>
19
20 struct convertible
21 {
22 convertible(int) {}
23 };
24
25 template <typename From, typename To>
26 bool is_convertible(bool has_conversion)
27 {
28 typedef typename boost::remove_reference<
29 typename boost::remove_const<From>::type
30 >::type from_rvalue;
31 typedef typename boost::add_reference<from_rvalue>::type from_lvalue;
32 typedef typename boost::add_const<from_lvalue>::type from_const_lvalue;
33
34 return
35 boost::is_convertible<from_rvalue, To>::value == has_conversion &&
36 boost::is_convertible<from_lvalue, To>::value == has_conversion &&
37 boost::is_convertible<from_const_lvalue, To>::value == has_conversion;
38 }
39
40 // is_constructible has a few requirements
41 #if !defined(BOOST_NO_CXX11_DECLTYPE) && \
42 !defined(BOOST_NO_CXX11_TEMPLATES) && \
43 !defined(BOOST_NO_SFINAE_EXPR)
44
45 #define FUSION_TEST_HAS_CONSTRUCTIBLE
46
47 template <typename To, typename... Args>
48 bool is_lvalue_constructible(bool has_constructor)
49 {
50 return has_constructor ==
51 boost::is_constructible<
52 To
53 , typename boost::add_reference<Args>::type...
54 >::value;
55 }
56
57 template <typename To, typename... Args>
58 bool is_constructible_impl(bool has_constructor)
59 {
60 return
61 boost::is_constructible<To, Args...>::value == has_constructor &&
62 is_lvalue_constructible<To, Args...>(has_constructor) &&
63 is_lvalue_constructible<
64 To, typename boost::add_const<Args>::type...
65 >(has_constructor);
66 }
67
68 template <typename To, typename... Args>
69 bool is_constructible(bool has_constructor)
70 {
71 return
72 is_constructible_impl<
73 To
74 , typename boost::remove_reference<
75 typename boost::remove_const<Args>::type
76 >::type...
77 >(has_constructor);
78 }
79
80 void test_constructible()
81 {
82 BOOST_TEST((is_constructible< FUSION_SEQUENCE<> >(true)));
83
84 BOOST_TEST((is_constructible< FUSION_SEQUENCE<int> >(true)));
85 BOOST_TEST((is_constructible<FUSION_SEQUENCE<int>, int>(true)));
86
87 BOOST_TEST((is_constructible<FUSION_SEQUENCE<convertible>, int>(true)));
88 BOOST_TEST((
89 is_constructible<FUSION_SEQUENCE<convertible>, convertible>(true)
90 ));
91
92 BOOST_TEST((
93 is_constructible<FUSION_SEQUENCE<int, int>, int, int>(true)
94 ));
95
96 BOOST_TEST((
97 is_constructible<FUSION_SEQUENCE<convertible, int>, int, int>(true)
98 ));
99 BOOST_TEST((
100 is_constructible<
101 FUSION_SEQUENCE<convertible, int>, convertible, int
102 >(true)
103 ));
104
105 BOOST_TEST((
106 is_constructible<FUSION_SEQUENCE<int, convertible>, int, int>(true)
107 ));
108 BOOST_TEST((
109 is_constructible<
110 FUSION_SEQUENCE<int, convertible>, int, convertible
111 >(true)
112 ));
113
114 BOOST_TEST((
115 is_constructible<
116 FUSION_SEQUENCE<convertible, convertible>, int, int
117 >(true)
118 ));
119 BOOST_TEST((
120 is_constructible<
121 FUSION_SEQUENCE<convertible, convertible>, convertible, int
122 >(true)
123 ));
124 BOOST_TEST((
125 is_constructible<
126 FUSION_SEQUENCE<convertible, convertible>, int, convertible
127 >(true)
128 ));
129 BOOST_TEST((
130 is_constructible<
131 FUSION_SEQUENCE<convertible, convertible>, convertible, convertible
132 >(true)
133 ));
134 }
135
136 #endif // is_constructible is available
137
138 void test_convertible(bool has_seq_conversion)
139 {
140 BOOST_TEST((is_convertible<int, FUSION_SEQUENCE<> >(false)));
141 BOOST_TEST((is_convertible<int, FUSION_SEQUENCE<int> >(false)));
142 BOOST_TEST((is_convertible<int, FUSION_SEQUENCE<const int&> >(false)));
143 BOOST_TEST((is_convertible<int, FUSION_SEQUENCE<convertible> >(false)));
144 BOOST_TEST((
145 is_convertible<int, FUSION_SEQUENCE<const convertible&> >(false)
146 ));
147 BOOST_TEST((is_convertible<int, FUSION_SEQUENCE<int, int> >(false)));
148 BOOST_TEST((
149 is_convertible<int, FUSION_SEQUENCE<const int&, const int&> >(false)
150 ));
151 BOOST_TEST((is_convertible<int, FUSION_SEQUENCE<convertible, int> >(false)));
152 BOOST_TEST((
153 is_convertible<int, FUSION_SEQUENCE<const convertible&, const int&> >(false)
154 ));
155 BOOST_TEST((is_convertible<int, FUSION_SEQUENCE<int, convertible> >(false)));
156 BOOST_TEST((
157 is_convertible<int, FUSION_SEQUENCE<const int&, const convertible&> >(false)
158 ));
159 BOOST_TEST((
160 is_convertible<int, FUSION_SEQUENCE<convertible, convertible> >(false)
161 ));
162 BOOST_TEST((
163 is_convertible<
164 int, FUSION_SEQUENCE<const convertible&, const convertible&>
165 >(false)
166 ));
167
168 BOOST_TEST((is_convertible<FUSION_SEQUENCE<>, FUSION_SEQUENCE<> >(true)));
169 BOOST_TEST((
170 is_convertible<FUSION_SEQUENCE<int>, FUSION_SEQUENCE<int> >(true)
171 ));
172 BOOST_TEST((
173 is_convertible<FUSION_SEQUENCE<int>, FUSION_SEQUENCE<const int&> >(true)
174 ));
175 BOOST_TEST((
176 is_convertible<FUSION_SEQUENCE<int>, FUSION_SEQUENCE<convertible> >(true)
177 ));
178 BOOST_TEST((
179 is_convertible<FUSION_SEQUENCE<int, int>, FUSION_SEQUENCE<int, int> >(true)
180 ));
181 BOOST_TEST((
182 is_convertible<
183 FUSION_SEQUENCE<int, int>, FUSION_SEQUENCE<const int&, const int&>
184 >(true)
185 ));
186 BOOST_TEST((
187 is_convertible<
188 FUSION_SEQUENCE<int, int>, FUSION_SEQUENCE<convertible, int>
189 >(true)
190 ));
191 BOOST_TEST((
192 is_convertible<
193 FUSION_SEQUENCE<int, int>, FUSION_SEQUENCE<int, convertible>
194 >(true)
195 ));
196 BOOST_TEST((
197 is_convertible<
198 FUSION_SEQUENCE<int, int>
199 , FUSION_SEQUENCE<convertible, convertible>
200 >(true)
201 ));
202
203 BOOST_TEST((
204 is_convertible<
205 FUSION_ALT_SEQUENCE<>, FUSION_SEQUENCE<>
206 >(has_seq_conversion)
207 ));
208 BOOST_TEST((
209 is_convertible<
210 FUSION_ALT_SEQUENCE<int>, FUSION_SEQUENCE<int>
211 >(has_seq_conversion)
212 ));
213 BOOST_TEST((
214 is_convertible<
215 FUSION_ALT_SEQUENCE<int>, FUSION_SEQUENCE<const int&>
216 >(has_seq_conversion)
217 ));
218 BOOST_TEST((
219 is_convertible<
220 FUSION_ALT_SEQUENCE<int>, FUSION_SEQUENCE<convertible>
221 >(has_seq_conversion)
222 ));
223 BOOST_TEST((
224 is_convertible<
225 FUSION_ALT_SEQUENCE<int, int>, FUSION_SEQUENCE<int, int>
226 >(has_seq_conversion)
227 ));
228 BOOST_TEST((
229 is_convertible<
230 FUSION_ALT_SEQUENCE<int, int>
231 , FUSION_SEQUENCE<const int&, const int&>
232 >(has_seq_conversion)
233 ));
234 BOOST_TEST((
235 is_convertible<
236 FUSION_ALT_SEQUENCE<int, int>, FUSION_SEQUENCE<convertible, int>
237 >(has_seq_conversion)
238 ));
239 BOOST_TEST((
240 is_convertible<
241 FUSION_ALT_SEQUENCE<int, int>, FUSION_SEQUENCE<int, convertible>
242 >(has_seq_conversion)
243 ));
244 BOOST_TEST((
245 is_convertible<
246 FUSION_ALT_SEQUENCE<int, int>
247 , FUSION_SEQUENCE<convertible, convertible>
248 >(has_seq_conversion)
249 ));
250 }
251