]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/callable_traits/test/is_invocable.cpp
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)
10 #include <boost/callable_traits/is_invocable.hpp>
13 #ifdef BOOST_CLBL_TRTS_GCC_OLDER_THAN_4_9_2
14 //gcc < 4.9 doesn't like the invoke_case pattern used here
23 template<bool Expect
, typename
... Args
>
25 template<typename Callable
>
26 void operator()(tag
<Callable
>) const {
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
...>()));
32 CT_ASSERT((Expect
== boost::callable_traits::is_invocable
<Callable
, Args
...>()));
38 template<typename Callable
, typename
... InvokeCases
>
40 using ignored
= int[];
41 ignored x
{(InvokeCases
{}(tag
<Callable
>{}),0)..., 0};
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>
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>
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>
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>
121 // MSVC doesn't handle cv + ref qualifiers in expression sfinae correctly
122 #ifndef BOOST_CLBL_TRTS_MSVC
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>
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>
160 #endif // #ifndef BOOST_CLBL_TRTS_MSVC
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>
182 run_tests
<decltype(f
)
183 ,invoke_case
<true, int>
184 ,invoke_case
<true, char>
185 ,invoke_case
<false, void*>
188 run_tests
<decltype(f
)&
189 ,invoke_case
<true, int>
190 ,invoke_case
<true, char>
191 ,invoke_case
<false, void*>
194 run_tests
<decltype(std::ref(f
))
195 ,invoke_case
<true, int>
196 ,invoke_case
<true, char>
197 ,invoke_case
<false, void*>
200 run_tests
<decltype(std::ref(f
))&
201 ,invoke_case
<true, int>
202 ,invoke_case
<true, char>
203 ,invoke_case
<false, void*>
206 run_tests
<decltype(std::ref(f
))&&
207 ,invoke_case
<true, int>
208 ,invoke_case
<true, char>
209 ,invoke_case
<false, void*>
212 run_tests
<decltype(std::ref(f
)) const &
213 ,invoke_case
<true, int>
214 ,invoke_case
<true, char>
215 ,invoke_case
<false, void*>
218 run_tests
<decltype(std::ref(f
)) const &&
219 ,invoke_case
<true, int>
220 ,invoke_case
<true, char>
221 ,invoke_case
<false, void*>
224 run_tests
<decltype(f
)&&
225 ,invoke_case
<true, int>
226 ,invoke_case
<true, char>
227 ,invoke_case
<false, void*>
230 run_tests
<decltype(f
) const &
231 ,invoke_case
<true, int>
232 ,invoke_case
<true, char>
233 ,invoke_case
<false, void*>
236 run_tests
<decltype(f
) const &&
237 ,invoke_case
<true, int>
238 ,invoke_case
<true, char>
239 ,invoke_case
<false, void*>
244 run_tests
<decltype(g
)
246 ,invoke_case
<false, char>
247 ,invoke_case
<false, void*>
250 run_tests
<decltype(g
)&
252 ,invoke_case
<false, char>
253 ,invoke_case
<false, void*>
256 run_tests
<decltype(std::ref(g
))
258 ,invoke_case
<false, char>
259 ,invoke_case
<false, void*>
262 run_tests
<decltype(std::ref(g
))&
264 ,invoke_case
<false, char>
265 ,invoke_case
<false, void*>
268 run_tests
<decltype(std::ref(g
))&&
270 ,invoke_case
<false, char>
271 ,invoke_case
<false, void*>
274 run_tests
<decltype(std::ref(g
)) const &
276 ,invoke_case
<false, char>
277 ,invoke_case
<false, void*>
280 run_tests
<decltype(std::ref(g
)) const &&
282 ,invoke_case
<false, char>
283 ,invoke_case
<false, void*>
286 run_tests
<decltype(g
)&&
288 ,invoke_case
<false, char>
289 ,invoke_case
<false, void*>
292 run_tests
<decltype(g
) const &
294 ,invoke_case
<false, char>
295 ,invoke_case
<false, void*>
298 run_tests
<decltype(g
) const &&
300 ,invoke_case
<false, char>
301 ,invoke_case
<false, void*>
304 // libc++ requires constructible types be passed to std::is_invocable
305 #ifndef _LIBCPP_VERSION
308 ,invoke_case
<true, int>
309 ,invoke_case
<true, char>
310 ,invoke_case
<false, void*>
313 run_tests
<void(int) const
314 ,invoke_case
<false, int>
315 ,invoke_case
<false, char>
316 ,invoke_case
<false, void*>
320 ,invoke_case
<false, int>
321 ,invoke_case
<false, char>
322 ,invoke_case
<false, 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>
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>
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>
381 #endif //#ifdef BOOST_CLBL_TRTS_GCC_OLDER_THAN_4_9_2