2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_DETAIL_IS_INVOCABLE_HPP
11 #define BOOST_BEAST_DETAIL_IS_INVOCABLE_HPP
13 #include <boost/asio/async_result.hpp>
14 #include <boost/type_traits/make_void.hpp>
15 #include <type_traits>
22 template<class R, class C, class ...A>
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,
30 template<class R, class C, class ...A>
32 is_invocable_test(C&& c, long, A&& ...a);
34 /** Metafunction returns `true` if F callable as R(A...)
39 is_invocable<T, void(std::string)>::value
43 template<class C, class F>
44 struct is_invocable : std::false_type
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>()...))
56 template<class CompletionToken, class Signature, class = void>
57 struct is_completion_token_for : std::false_type
63 template<class...AnyArgs>
64 void operator()(AnyArgs&&...);
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&>())