]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/callable_traits/test/is_invocable.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / callable_traits / test / is_invocable.cpp
1 /*
2 Copyright Barrett Adair 2016-2017
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt)
5 */
6
7 #include <type_traits>
8 #include <functional>
9 #include <utility>
10 #include <boost/callable_traits/is_invocable.hpp>
11 #include "test.hpp"
12
13 #ifdef BOOST_CLBL_TRTS_GCC_OLDER_THAN_4_9_2
14 //gcc < 4.9 doesn't like the invoke_case pattern used here
15 int main(){}
16 #else
17
18 template<typename T>
19 struct tag {
20 using type = T;
21 };
22
23 template<bool Expect, typename... Args>
24 struct invoke_case {
25 template<typename Callable>
26 void operator()(tag<Callable>) const {
27
28 // when available, test parity with std implementation (c++2a breaks our expectations but we still match std impl)
29 #if defined(__cpp_lib_is_invocable) || __cplusplus >= 201707L
30 CT_ASSERT((std::is_invocable<Callable, Args...>() == boost::callable_traits::is_invocable<Callable, Args...>()));
31 #else
32 CT_ASSERT((Expect == boost::callable_traits::is_invocable<Callable, Args...>()));
33 #endif
34
35 }
36 };
37
38 template<typename Callable, typename... InvokeCases>
39 void run_tests() {
40 using ignored = int[];
41 ignored x {(InvokeCases{}(tag<Callable>{}),0)..., 0};
42 (void)x;
43 }
44
45 struct foo {};
46
47 int main() {
48
49 run_tests<void(foo::*)()
50 ,invoke_case<true, foo>
51 ,invoke_case<true, foo*>
52 ,invoke_case<true, foo&>
53 ,invoke_case<true, foo&&>
54 ,invoke_case<true, std::reference_wrapper<foo>>
55 ,invoke_case<false, foo const>
56 ,invoke_case<false, foo const*>
57 ,invoke_case<false, foo const&>
58 ,invoke_case<false, foo const&&>
59 ,invoke_case<false, std::reference_wrapper<foo const>>
60 ,invoke_case<false, foo, int>
61 ,invoke_case<false, foo*, int>
62 ,invoke_case<false, foo&, int>
63 ,invoke_case<false, foo&&, int>
64 ,invoke_case<false, std::reference_wrapper<foo>, int>
65 >();
66
67 run_tests<void(foo::*)() LREF
68 ,invoke_case<false, foo>
69 ,invoke_case<true, foo*>
70 ,invoke_case<true, foo&>
71 ,invoke_case<false, foo&&>
72 ,invoke_case<true, std::reference_wrapper<foo>>
73 ,invoke_case<false, foo const>
74 ,invoke_case<false, foo const*>
75 ,invoke_case<false, foo const&>
76 ,invoke_case<false, foo const&&>
77 ,invoke_case<false, std::reference_wrapper<foo const>>
78 ,invoke_case<false, foo, int>
79 ,invoke_case<false, foo*, int>
80 ,invoke_case<false, foo&, int>
81 ,invoke_case<false, foo&&, int>
82 ,invoke_case<false, std::reference_wrapper<foo>, int>
83 >();
84
85 run_tests<void(foo::*)() RREF
86 ,invoke_case<true, foo>
87 ,invoke_case<false, foo*>
88 ,invoke_case<false, foo&>
89 ,invoke_case<true, foo&&>
90 ,invoke_case<false, std::reference_wrapper<foo>>
91 ,invoke_case<false, foo const>
92 ,invoke_case<false, foo const*>
93 ,invoke_case<false, foo const&>
94 ,invoke_case<false, foo const&&>
95 ,invoke_case<false, std::reference_wrapper<foo const>>
96 ,invoke_case<false, foo, int>
97 ,invoke_case<false, foo*, int>
98 ,invoke_case<false, foo&, int>
99 ,invoke_case<false, foo&&, int>
100 ,invoke_case<false, std::reference_wrapper<foo>, int>
101 >();
102
103 run_tests<void(foo::*)() const
104 ,invoke_case<true, foo>
105 ,invoke_case<true, foo*>
106 ,invoke_case<true, foo&>
107 ,invoke_case<true, foo&&>
108 ,invoke_case<true, std::reference_wrapper<foo>>
109 ,invoke_case<true, foo const>
110 ,invoke_case<true, foo const*>
111 ,invoke_case<true, foo const&>
112 ,invoke_case<true, foo const&&>
113 ,invoke_case<true, std::reference_wrapper<foo const>>
114 ,invoke_case<false, foo, int>
115 ,invoke_case<false, foo*, int>
116 ,invoke_case<false, foo&, int>
117 ,invoke_case<false, foo&&, int>
118 ,invoke_case<false, std::reference_wrapper<foo>, int>
119 >();
120
121 // MSVC doesn't handle cv + ref qualifiers in expression sfinae correctly
122 #ifndef BOOST_CLBL_TRTS_MSVC
123
124 run_tests<void(foo::*)() const LREF
125 ,invoke_case<false, foo>
126 ,invoke_case<true, foo*>
127 ,invoke_case<true, foo&>
128 ,invoke_case<false, foo&&>
129 ,invoke_case<true, std::reference_wrapper<foo>>
130 ,invoke_case<false, foo const>
131 ,invoke_case<true, foo const*>
132 ,invoke_case<true, foo const&>
133 ,invoke_case<false, foo const&&>
134 ,invoke_case<true, std::reference_wrapper<foo const>>
135 ,invoke_case<false, foo, int>
136 ,invoke_case<false, foo*, int>
137 ,invoke_case<false, foo&, int>
138 ,invoke_case<false, foo&&, int>
139 ,invoke_case<false, std::reference_wrapper<foo>, int>
140 >();
141
142 run_tests<void(foo::*)() const RREF
143 ,invoke_case<true, foo>
144 ,invoke_case<false, foo*>
145 ,invoke_case<false, foo&>
146 ,invoke_case<true, foo&&>
147 ,invoke_case<false, std::reference_wrapper<foo>>
148 ,invoke_case<true, foo const>
149 ,invoke_case<false, foo const*>
150 ,invoke_case<false, foo const&>
151 ,invoke_case<true, foo const&&>
152 ,invoke_case<false, std::reference_wrapper<foo const>>
153 ,invoke_case<false, foo, int>
154 ,invoke_case<false, foo*, int>
155 ,invoke_case<false, foo&, int>
156 ,invoke_case<false, foo&&, int>
157 ,invoke_case<false, std::reference_wrapper<foo>, int>
158 >();
159
160 #endif // #ifndef BOOST_CLBL_TRTS_MSVC
161
162 run_tests<int
163 ,invoke_case<false, foo>
164 ,invoke_case<false, foo*>
165 ,invoke_case<false, foo&>
166 ,invoke_case<false, foo&&>
167 ,invoke_case<false, std::reference_wrapper<foo>>
168 ,invoke_case<false, foo const>
169 ,invoke_case<false, foo const*>
170 ,invoke_case<false, foo const&>
171 ,invoke_case<false, foo const&&>
172 ,invoke_case<false, std::reference_wrapper<foo const>>
173 ,invoke_case<false, foo, int>
174 ,invoke_case<false, foo*, int>
175 ,invoke_case<false, foo&, int>
176 ,invoke_case<false, foo&&, int>
177 ,invoke_case<false, std::reference_wrapper<foo>, int>
178 >();
179
180 auto f = [](int){};
181
182 run_tests<decltype(f)
183 ,invoke_case<true, int>
184 ,invoke_case<true, char>
185 ,invoke_case<false, void*>
186 >();
187
188 run_tests<decltype(f)&
189 ,invoke_case<true, int>
190 ,invoke_case<true, char>
191 ,invoke_case<false, void*>
192 >();
193
194 run_tests<decltype(std::ref(f))
195 ,invoke_case<true, int>
196 ,invoke_case<true, char>
197 ,invoke_case<false, void*>
198 >();
199
200 run_tests<decltype(std::ref(f))&
201 ,invoke_case<true, int>
202 ,invoke_case<true, char>
203 ,invoke_case<false, void*>
204 >();
205
206 run_tests<decltype(std::ref(f))&&
207 ,invoke_case<true, int>
208 ,invoke_case<true, char>
209 ,invoke_case<false, void*>
210 >();
211
212 run_tests<decltype(std::ref(f)) const &
213 ,invoke_case<true, int>
214 ,invoke_case<true, char>
215 ,invoke_case<false, void*>
216 >();
217
218 run_tests<decltype(std::ref(f)) const &&
219 ,invoke_case<true, int>
220 ,invoke_case<true, char>
221 ,invoke_case<false, void*>
222 >();
223
224 run_tests<decltype(f)&&
225 ,invoke_case<true, int>
226 ,invoke_case<true, char>
227 ,invoke_case<false, void*>
228 >();
229
230 run_tests<decltype(f) const &
231 ,invoke_case<true, int>
232 ,invoke_case<true, char>
233 ,invoke_case<false, void*>
234 >();
235
236 run_tests<decltype(f) const &&
237 ,invoke_case<true, int>
238 ,invoke_case<true, char>
239 ,invoke_case<false, void*>
240 >();
241
242 auto g = [](){};
243
244 run_tests<decltype(g)
245 ,invoke_case<true>
246 ,invoke_case<false, char>
247 ,invoke_case<false, void*>
248 >();
249
250 run_tests<decltype(g)&
251 ,invoke_case<true>
252 ,invoke_case<false, char>
253 ,invoke_case<false, void*>
254 >();
255
256 run_tests<decltype(std::ref(g))
257 ,invoke_case<true>
258 ,invoke_case<false, char>
259 ,invoke_case<false, void*>
260 >();
261
262 run_tests<decltype(std::ref(g))&
263 ,invoke_case<true>
264 ,invoke_case<false, char>
265 ,invoke_case<false, void*>
266 >();
267
268 run_tests<decltype(std::ref(g))&&
269 ,invoke_case<true>
270 ,invoke_case<false, char>
271 ,invoke_case<false, void*>
272 >();
273
274 run_tests<decltype(std::ref(g)) const &
275 ,invoke_case<true>
276 ,invoke_case<false, char>
277 ,invoke_case<false, void*>
278 >();
279
280 run_tests<decltype(std::ref(g)) const &&
281 ,invoke_case<true>
282 ,invoke_case<false, char>
283 ,invoke_case<false, void*>
284 >();
285
286 run_tests<decltype(g)&&
287 ,invoke_case<true>
288 ,invoke_case<false, char>
289 ,invoke_case<false, void*>
290 >();
291
292 run_tests<decltype(g) const &
293 ,invoke_case<true>
294 ,invoke_case<false, char>
295 ,invoke_case<false, void*>
296 >();
297
298 run_tests<decltype(g) const &&
299 ,invoke_case<true>
300 ,invoke_case<false, char>
301 ,invoke_case<false, void*>
302 >();
303
304 // libc++ requires constructible types be passed to std::is_invocable
305 #ifndef _LIBCPP_VERSION
306
307 run_tests<void(int)
308 ,invoke_case<true, int>
309 ,invoke_case<true, char>
310 ,invoke_case<false, void*>
311 >();
312
313 run_tests<void(int) const
314 ,invoke_case<false, int>
315 ,invoke_case<false, char>
316 ,invoke_case<false, void*>
317 >();
318
319 run_tests<void()
320 ,invoke_case<false, int>
321 ,invoke_case<false, char>
322 ,invoke_case<false, void*>
323 >();
324
325 run_tests<void
326 ,invoke_case<false, foo>
327 ,invoke_case<false, foo*>
328 ,invoke_case<false, foo&>
329 ,invoke_case<false, foo&&>
330 ,invoke_case<false, std::reference_wrapper<foo>>
331 ,invoke_case<false, foo const>
332 ,invoke_case<false, foo const*>
333 ,invoke_case<false, foo const&>
334 ,invoke_case<false, foo const&&>
335 ,invoke_case<false, std::reference_wrapper<foo const>>
336 ,invoke_case<false, foo, int>
337 ,invoke_case<false, foo*, int>
338 ,invoke_case<false, foo&, int>
339 ,invoke_case<false, foo&&, int>
340 ,invoke_case<false, std::reference_wrapper<foo>, int>
341 >();
342 #endif
343
344 run_tests<int
345 ,invoke_case<false, foo>
346 ,invoke_case<false, foo*>
347 ,invoke_case<false, foo&>
348 ,invoke_case<false, foo&&>
349 ,invoke_case<false, std::reference_wrapper<foo>>
350 ,invoke_case<false, foo const>
351 ,invoke_case<false, foo const*>
352 ,invoke_case<false, foo const&>
353 ,invoke_case<false, foo const&&>
354 ,invoke_case<false, std::reference_wrapper<foo const>>
355 ,invoke_case<false, foo, int>
356 ,invoke_case<false, foo*, int>
357 ,invoke_case<false, foo&, int>
358 ,invoke_case<false, foo&&, int>
359 ,invoke_case<false, std::reference_wrapper<foo>, int>
360 >();
361
362 run_tests<void*
363 ,invoke_case<false, foo>
364 ,invoke_case<false, foo*>
365 ,invoke_case<false, foo&>
366 ,invoke_case<false, foo&&>
367 ,invoke_case<false, std::reference_wrapper<foo>>
368 ,invoke_case<false, foo const>
369 ,invoke_case<false, foo const*>
370 ,invoke_case<false, foo const&>
371 ,invoke_case<false, foo const&&>
372 ,invoke_case<false, std::reference_wrapper<foo const>>
373 ,invoke_case<false, foo, int>
374 ,invoke_case<false, foo*, int>
375 ,invoke_case<false, foo&, int>
376 ,invoke_case<false, foo&&, int>
377 ,invoke_case<false, std::reference_wrapper<foo>, int>
378 >();
379 }
380
381 #endif //#ifdef BOOST_CLBL_TRTS_GCC_OLDER_THAN_4_9_2