]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
1 | // |
2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | |
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 | // Official repository: https://github.com/boostorg/beast | |
8 | // | |
9 | ||
10 | #ifndef BOOST_BEAST_DETAIL_IS_INVOCABLE_HPP | |
11 | #define BOOST_BEAST_DETAIL_IS_INVOCABLE_HPP | |
12 | ||
20effc67 TL |
13 | #include <boost/asio/async_result.hpp> |
14 | #include <boost/type_traits/make_void.hpp> | |
92f5a8d4 TL |
15 | #include <type_traits> |
16 | #include <utility> | |
17 | ||
18 | namespace boost { | |
19 | namespace beast { | |
20 | namespace detail { | |
21 | ||
22 | template<class R, class C, class ...A> | |
23 | auto | |
24 | is_invocable_test(C&& c, int, A&& ...a) | |
25 | -> decltype(std::is_convertible< | |
26 | decltype(c(std::forward<A>(a)...)), R>::value || | |
27 | std::is_same<R, void>::value, | |
28 | std::true_type()); | |
29 | ||
30 | template<class R, class C, class ...A> | |
31 | std::false_type | |
32 | is_invocable_test(C&& c, long, A&& ...a); | |
33 | ||
34 | /** Metafunction returns `true` if F callable as R(A...) | |
35 | ||
36 | Example: | |
37 | ||
38 | @code | |
39 | is_invocable<T, void(std::string)>::value | |
40 | @endcode | |
41 | */ | |
42 | /** @{ */ | |
43 | template<class C, class F> | |
44 | struct is_invocable : std::false_type | |
45 | { | |
46 | }; | |
47 | ||
48 | template<class C, class R, class ...A> | |
49 | struct is_invocable<C, R(A...)> | |
50 | : decltype(is_invocable_test<R>( | |
51 | std::declval<C>(), 1, std::declval<A>()...)) | |
52 | { | |
53 | }; | |
54 | /** @} */ | |
55 | ||
20effc67 TL |
56 | template<class CompletionToken, class Signature, class = void> |
57 | struct is_completion_token_for : std::false_type | |
58 | { | |
59 | }; | |
60 | ||
61 | struct any_initiation | |
62 | { | |
63 | template<class...AnyArgs> | |
64 | void operator()(AnyArgs&&...); | |
65 | }; | |
66 | ||
67 | template<class CompletionToken, class R, class...Args> | |
68 | struct is_completion_token_for< | |
69 | CompletionToken, R(Args...), boost::void_t<decltype( | |
70 | boost::asio::async_initiate<CompletionToken, R(Args...)>( | |
71 | any_initiation(), std::declval<CompletionToken&>()) | |
72 | )>> : std::true_type | |
73 | { | |
74 | }; | |
75 | ||
92f5a8d4 TL |
76 | } // detail |
77 | } // beast | |
78 | } // boost | |
79 | ||
80 | #endif |