is_invocable.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*=============================================================================
  2. Copyright (c) 2014 Paul Fultz II
  3. is_invocable.h
  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. #ifndef BOOST_HOF_GUARD_IS_CALLABLE_H
  8. #define BOOST_HOF_GUARD_IS_CALLABLE_H
  9. /// is_invocable
  10. /// ===========
  11. ///
  12. /// Description
  13. /// -----------
  14. ///
  15. /// The `is_invocable` metafunction checks if the function is callable with
  16. /// certain parameters.
  17. ///
  18. /// Requirements
  19. /// ------------
  20. ///
  21. /// F must be:
  22. ///
  23. /// * [Invocable](Invocable)
  24. ///
  25. /// Synopsis
  26. /// --------
  27. ///
  28. /// template<class F, class... Ts>
  29. /// struct is_invocable;
  30. ///
  31. /// Example
  32. /// -------
  33. ///
  34. /// #include <boost/hof.hpp>
  35. /// using namespace boost::hof;
  36. ///
  37. /// struct is_invocable_class
  38. /// {
  39. /// void operator()(int) const
  40. /// {
  41. /// }
  42. /// };
  43. /// static_assert(is_invocable<is_invocable_class, int>(), "Not callable");
  44. ///
  45. /// int main() {}
  46. ///
  47. #include <boost/hof/detail/can_be_called.hpp>
  48. #include <boost/hof/apply.hpp>
  49. namespace boost { namespace hof {
  50. template<class F, class... Ts>
  51. struct is_invocable
  52. : detail::can_be_called<detail::apply_f, F, Ts...>
  53. {};
  54. template<class F, class... Ts, class... Us>
  55. struct is_invocable<F(Ts...), Us...>
  56. {
  57. static_assert(!std::is_same<F, F>::value,
  58. "The is_invocable<F(Args...)> form is not supported because it is problematic."
  59. "Please use is_invocable<F, Args...> instead."
  60. );
  61. };
  62. }} // namespace boost::hof
  63. #endif