function_type.hpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_FUNCTION_TYPE_HPP
  7. #define BOOST_CLBL_TRTS_FUNCTION_TYPE_HPP
  8. #include <boost/callable_traits/detail/core.hpp>
  9. namespace boost { namespace callable_traits {
  10. //[ function_type_hpp
  11. /*`[section:ref_function_type function_type]
  12. [heading Header]
  13. ``#include <boost/callable_traits/function_type.hpp>``
  14. [heading Definition]
  15. */
  16. template<typename T>
  17. using function_type_t = //see below
  18. //<-
  19. detail::try_but_fail_if_invalid<typename detail::traits<
  20. detail::shallow_decay<T>>::function_type,
  21. cannot_determine_parameters_for_this_type>;
  22. namespace detail {
  23. template<typename T, typename = std::false_type>
  24. struct function_type_impl {};
  25. template<typename T>
  26. struct function_type_impl <T, typename std::is_same<
  27. function_type_t<T>, detail::dummy>::type>
  28. {
  29. using type = function_type_t<T>;
  30. };
  31. }
  32. //->
  33. template<typename T>
  34. struct function_type : detail::function_type_impl<T> {};
  35. //<-
  36. }} // namespace boost::callable_traits
  37. //->
  38. /*`
  39. [heading Constraints]
  40. * `T` must be one of the following:
  41. * function
  42. * function pointer
  43. * function reference
  44. * member function pointer
  45. * member data pointer
  46. * user-defined type with a non-overloaded `operator()`
  47. * type of a non-generic lambda
  48. [heading Behavior]
  49. * When the constraints are violated, a substitution failure occurs.
  50. * When `T` is a function, the aliased type is identical to `T`, except that the aliased function type will not have member qualifiers or the `transaction_safe` specifier.
  51. * When `T` is a function pointer, the aliased type is equivalent to `std::remove_pointer_t<T>`.
  52. * When `T` is a function reference, the aliased type is equivalent to `std::remove_reference_t<T>`.
  53. * When `T` is a function object, the aliased type is a function type with the same return type and parameter list as `T`'s `operator()`.
  54. * When `T` is a member function pointer, the aliased type is a function type with the same return type as `T`, and the first parameter is a reference to the parent class of `T`, qualified according to the member qualifiers on `T`. The subsequent parameters, if any, are the parameter types of `T`.
  55. * When `T` is a member data pointer, the aliased type is a function type returning the underlying member type of `T`, taking a single parameter, which is a `const` reference to the parent type of `T`.
  56. * In all cases, the aliased function type will not have member qualifiers, and will not have the `transaction_safe` specifier.
  57. [heading Input/Output Examples]
  58. [table
  59. [[`T`] [`function_type_t<T>`]]
  60. [[`void(int)`] [`void(int)`]]
  61. [[`void(int) const`] [`void(int)`]]
  62. [[`void(int) transaction_safe`] [`void(int)`]]
  63. [[`void(*const &)(int)`] [`void(int)`]]
  64. [[`void(&)(int)`] [`void(int)`]]
  65. [[`void(* volatile)()`] [`void()`]]
  66. [[`int(foo::*)(int)`] [`int(foo&, int)`]]
  67. [[`int(foo::*)(int) const`] [`int(const foo&, int)`]]
  68. [[`void(foo::*)() volatile &&`] [`void(volatile foo&&)`]]
  69. [[`int foo::*`] [`int(const foo&)`]]
  70. [[`const int foo::*`] [`int(const foo&)`]]
  71. [[`int`] [(substitution failure)]]
  72. ]
  73. [heading Example Program]
  74. [import ../example/function_type.cpp]
  75. [function_type]
  76. [endsect]
  77. */
  78. //]
  79. #endif