is_invocable.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 <type_traits>
  12. #include <utility>
  13. namespace boost {
  14. namespace beast {
  15. namespace detail {
  16. template<class R, class C, class ...A>
  17. auto
  18. is_invocable_test(C&& c, int, A&& ...a)
  19. -> decltype(std::is_convertible<
  20. decltype(c(std::forward<A>(a)...)), R>::value ||
  21. std::is_same<R, void>::value,
  22. std::true_type());
  23. template<class R, class C, class ...A>
  24. std::false_type
  25. is_invocable_test(C&& c, long, A&& ...a);
  26. /** Metafunction returns `true` if F callable as R(A...)
  27. Example:
  28. @code
  29. is_invocable<T, void(std::string)>::value
  30. @endcode
  31. */
  32. /** @{ */
  33. template<class C, class F>
  34. struct is_invocable : std::false_type
  35. {
  36. };
  37. template<class C, class R, class ...A>
  38. struct is_invocable<C, R(A...)>
  39. : decltype(is_invocable_test<R>(
  40. std::declval<C>(), 1, std::declval<A>()...))
  41. {
  42. };
  43. /** @} */
  44. } // detail
  45. } // beast
  46. } // boost
  47. #endif