return_type.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_RESULT_OF_HPP
  7. #define BOOST_CLBL_TRTS_RESULT_OF_HPP
  8. #include <boost/callable_traits/detail/core.hpp>
  9. namespace boost { namespace callable_traits {
  10. BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(return_type)
  11. BOOST_CLBL_TRTS_SFINAE_MSG(return_type, unable_to_determine_return_type)
  12. //[ return_type_hpp
  13. /*`
  14. [section:ref_return_type return_type]
  15. [heading Header]
  16. ``#include <boost/callable_traits/return_type.hpp>``
  17. [heading Definition]
  18. */
  19. template<typename T>
  20. using return_type_t = //see below
  21. //<-
  22. detail::try_but_fail_if_invalid<
  23. typename detail::traits<detail::shallow_decay<T>>::return_type,
  24. unable_to_determine_return_type>;
  25. namespace detail {
  26. template<typename T, typename = std::false_type>
  27. struct return_type_impl {};
  28. template<typename T>
  29. struct return_type_impl <T, typename std::is_same<
  30. return_type_t<T>, detail::dummy>::type>
  31. {
  32. using type = return_type_t<T>;
  33. };
  34. }
  35. //->
  36. template<typename T>
  37. struct return_type : detail::return_type_impl<T> {};
  38. //<-
  39. }} // namespace boost::callable_traits
  40. //->
  41. /*`
  42. [heading Constraints]
  43. * `T` must be one of the following:
  44. * function
  45. * function pointer
  46. * function reference
  47. * member function pointer
  48. * member data pointer
  49. * user-defined type with a non-overloaded `operator()`
  50. * type of a non-generic lambda
  51. [heading Behavior]
  52. * When the constraints are violated, a substitution failure occurs.
  53. * The aliased type is the return type of `T`.
  54. [heading Input/Output Examples]
  55. [table
  56. [[`T`] [`return_type_t<T, std::tuple>`]]
  57. [[`void()`] [`void`]]
  58. [[`float(*)()`] [`float`]]
  59. [[`const char*(&)()`] [`const char *`]]
  60. [[`int(foo::*)() const`] [`int`]]
  61. [[`int`] [(substitution failure)]]
  62. [[`int (*const)()`] [(substitution failure)]]
  63. ]
  64. [heading Example Program]
  65. [import ../example/return_type.cpp]
  66. [return_type]
  67. [endsect]
  68. */
  69. //]
  70. #endif // #ifndef BOOST_CLBL_TRTS_RESULT_OF_HPP