is_invocable.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #ifndef BOOST_BEAST_DETAIL_IS_INVOCABLE_HPP
  10. #define BOOST_BEAST_DETAIL_IS_INVOCABLE_HPP
  11. #include <boost/asio/async_result.hpp>
  12. #include <boost/type_traits/make_void.hpp>
  13. #include <type_traits>
  14. #include <utility>
  15. namespace boost {
  16. namespace beast {
  17. namespace detail {
  18. template<class R, class C, class ...A>
  19. auto
  20. is_invocable_test(C&& c, int, A&& ...a)
  21. -> decltype(std::is_convertible<
  22. decltype(c(std::forward<A>(a)...)), R>::value ||
  23. std::is_same<R, void>::value,
  24. std::true_type());
  25. template<class R, class C, class ...A>
  26. std::false_type
  27. is_invocable_test(C&& c, long, A&& ...a);
  28. /** Metafunction returns `true` if F callable as R(A...)
  29. Example:
  30. @code
  31. is_invocable<T, void(std::string)>::value
  32. @endcode
  33. */
  34. /** @{ */
  35. template<class C, class F>
  36. struct is_invocable : std::false_type
  37. {
  38. };
  39. template<class C, class R, class ...A>
  40. struct is_invocable<C, R(A...)>
  41. : decltype(is_invocable_test<R>(
  42. std::declval<C>(), 1, std::declval<A>()...))
  43. {
  44. };
  45. /** @} */
  46. template<class CompletionToken, class Signature, class = void>
  47. struct is_completion_token_for : std::false_type
  48. {
  49. };
  50. struct any_initiation
  51. {
  52. template<class...AnyArgs>
  53. void operator()(AnyArgs&&...);
  54. };
  55. template<class CompletionToken, class R, class...Args>
  56. struct is_completion_token_for<
  57. CompletionToken, R(Args...), boost::void_t<decltype(
  58. boost::asio::async_initiate<CompletionToken, R(Args...)>(
  59. any_initiation(), std::declval<CompletionToken&>())
  60. )>> : std::true_type
  61. {
  62. };
  63. } // detail
  64. } // beast
  65. } // boost
  66. #endif