is_invocable.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. @Copyright Barrett Adair 2015-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)
  5. */
  6. #ifndef BOOST_CLBL_TRTS_IS_INVOCABLE_HPP
  7. #define BOOST_CLBL_TRTS_IS_INVOCABLE_HPP
  8. #include <boost/callable_traits/detail/core.hpp>
  9. #include <boost/callable_traits/detail/is_invocable_impl.hpp>
  10. namespace boost { namespace callable_traits {
  11. //[ is_invocable_hpp
  12. /*`[section:ref_is_invocable is_invocable]
  13. [heading Header]
  14. ``#include <boost/callable_traits/is_invocable.hpp>``
  15. [heading Definition]
  16. */
  17. // inherits from either std::true_type or std::false_type
  18. template<typename T, typename... Args>
  19. struct is_invocable;
  20. // inherits from either std::true_type or std::false_type
  21. template<typename Ret, typename T, typename... Args>
  22. struct is_invocable_r;
  23. //<-
  24. template<typename T, typename... Args>
  25. struct is_invocable : detail::is_invocable_impl<T, Args...>::type {
  26. using type = typename detail::is_invocable_impl<T, Args...>::type;
  27. };
  28. template<typename Ret, typename T, typename... Args>
  29. struct is_invocable_r
  30. : detail::is_invocable_r_impl<
  31. typename detail::is_invocable_impl<T, Args...>::type, Ret, T, Args...>::type
  32. {
  33. using type = typename detail::is_invocable_r_impl<
  34. typename detail::is_invocable_impl<T, Args...>::type, Ret, T, Args...>::type;
  35. };
  36. #ifdef BOOST_CLBL_TRTS_DISABLE_VARIABLE_TEMPLATES
  37. template<typename T, typename... Args>
  38. struct is_invocable_v {
  39. static_assert(std::is_same<T, detail::dummy>::value,
  40. "Variable templates not supported on this compiler.");
  41. };
  42. template<typename Ret, typename T, typename... Args>
  43. struct is_invocable_r_v {
  44. static_assert(std::is_same<T, detail::dummy>::value,
  45. "Variable templates not supported on this compiler.");
  46. };
  47. #else
  48. //->
  49. // only available when variable templates are supported
  50. template<typename T, typename... Args>
  51. //<-
  52. BOOST_CLBL_TRAITS_INLINE_VAR
  53. //->
  54. constexpr bool is_invocable_v = //see below
  55. //<-
  56. detail::is_invocable_impl<T, Args...>::type::value;
  57. //->
  58. // only available when variable templates are supported
  59. template<typename Ret, typename T, typename... Args>
  60. //<-
  61. BOOST_CLBL_TRAITS_INLINE_VAR
  62. //->
  63. constexpr bool is_invocable_r_v = //see below
  64. //<-
  65. detail::is_invocable_r_impl<
  66. typename detail::is_invocable_impl<T, Args...>::type,
  67. Ret, T, Args...>::type::value;
  68. #endif
  69. }} // namespace boost::callable_traits
  70. //->
  71. /*`
  72. [heading Constraints]
  73. * none
  74. [heading Behavior]
  75. * standalone c++11 implementation of c++17 `std::is_invocable`, `std::is_invocable_r`
  76. [note ref-qualified overloads of `operator()` with different signatures are not handled correctly yet.]
  77. [heading Example Program]
  78. [import ../example/is_invocable.cpp]
  79. [is_invocable]
  80. [endsect]
  81. */
  82. //]
  83. #endif // #ifndef BOOST_CLBL_TRTS_IS_INVOCABLE_HPP