apply_return.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_APPLY_RETURN_HPP
  7. #define BOOST_CLBL_TRTS_APPLY_RETURN_HPP
  8. #include <boost/callable_traits/detail/core.hpp>
  9. namespace boost { namespace callable_traits {
  10. BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(apply_return)
  11. BOOST_CLBL_TRTS_SFINAE_MSG(apply_return, invalid_types_for_apply_return)
  12. namespace detail {
  13. template<typename T, typename R>
  14. struct apply_return_helper {
  15. using type = typename detail::traits<T>::template apply_return<R>;
  16. };
  17. //special case
  18. template<typename... Args, typename R>
  19. struct apply_return_helper<std::tuple<Args...>, R> {
  20. using type = R(Args...);
  21. };
  22. }
  23. //[ apply_return_hpp
  24. /*`
  25. [section:ref_apply_return apply_return]
  26. [heading Header]
  27. ``#include <boost/callable_traits/apply_return.hpp>``
  28. [heading Definition]
  29. */
  30. template<typename T, typename R>
  31. using apply_return_t = //see below
  32. //<-
  33. detail::try_but_fail_if_invalid<
  34. typename detail::apply_return_helper<T, R>::type,
  35. invalid_types_for_apply_return>;
  36. namespace detail {
  37. template<typename T, typename R, typename = std::false_type>
  38. struct apply_return_impl {};
  39. template<typename T, typename R>
  40. struct apply_return_impl <T, R, typename std::is_same<
  41. apply_return_t<T, R>, detail::dummy>::type>
  42. {
  43. using type = apply_return_t<T, R>;
  44. };
  45. }
  46. //->
  47. template<typename T, typename R>
  48. struct apply_return : detail::apply_return_impl<T, R> {};
  49. //<-
  50. }} // namespace boost::callable_traits
  51. //->
  52. /*`
  53. [heading Constraints]
  54. * `T` must one of the following:
  55. * `std::tuple` template instantiation
  56. * function
  57. * function pointer
  58. * function reference
  59. * member function pointer
  60. * member data pointer
  61. * If `T` is a pointer, it may not be cv/ref qualified
  62. [heading Behavior]
  63. * When `T` is `std::tuple<Args...>`, the aliased type is `R(Args...)`.
  64. * When `T` is a function, function pointer, function reference, or member function pointer, the aliased type's return type is `R`, but is otherwise identical to `T`.
  65. * When `T` is a member data pointer of class `foo` to a `U` type (such that `T` is `U foo::*`), the aliased type is `R foo::*`.
  66. [heading Input/Output Examples]
  67. [table
  68. [[`T`] [`apply_return_t<T, float>`]]
  69. [[`std::tuple<int, int>`] [`float(int, int)`]]
  70. [[`int()`] [`float()`]]
  71. [[`int (&)()`] [`float(&)()`]]
  72. [[`int (*)()`] [`float(*)()`]]
  73. [[`int (*)(...)`] [`float(*)()`]]
  74. [[`int(foo::*)()`] [`float(foo::*)()`]]
  75. [[`int(foo::*)() &`] [`float(foo::*)() &`]]
  76. [[`int(foo::*)() &&`] [`float(foo::*)() &&`]]
  77. [[`int(foo::*)() const`] [`float(foo::*)() const`]]
  78. [[`int(foo::*)() transaction_safe`] [`float(foo::*)() transaction_safe`]]
  79. [[`int foo::*`] [`float foo::*`]]
  80. [[`int`] [(substitution failure)]]
  81. [[`int (*const)()`] [(substitution failure)]]
  82. ]
  83. [heading Example Program]
  84. [/import ../example/apply_return.cpp]
  85. [apply_return]
  86. [endsect]
  87. */
  88. //]
  89. #endif