has_void_return.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_HAS_VOID_RETURN_HPP
  7. #define BOOST_CLBL_TRTS_HAS_VOID_RETURN_HPP
  8. #include <boost/callable_traits/detail/core.hpp>
  9. namespace boost { namespace callable_traits {
  10. //[ has_void_return_hpp
  11. /*`[section:ref_has_void_return has_void_return]
  12. [heading Header]
  13. ``#include <boost/callable_traits/has_void_return.hpp>``
  14. [heading Definition]
  15. */
  16. // inherits from either std::true_type or std::false_type
  17. template<typename T>
  18. struct has_void_return;
  19. //<-
  20. template<typename T>
  21. struct has_void_return
  22. : std::is_same<typename detail::traits<
  23. detail::shallow_decay<T>>::return_type, void> {};
  24. #ifdef BOOST_CLBL_TRTS_DISABLE_VARIABLE_TEMPLATES
  25. template<typename T>
  26. struct has_void_return_v {
  27. static_assert(std::is_same<T, detail::dummy>::value,
  28. "Variable templates not supported on this compiler.");
  29. };
  30. #else
  31. //->
  32. // only available when variable templates are supported
  33. template<typename T>
  34. //<-
  35. BOOST_CLBL_TRAITS_INLINE_VAR
  36. //->
  37. constexpr bool has_void_return_v = //see below
  38. //<-
  39. std::is_same<typename detail::traits<
  40. detail::shallow_decay<T>>::return_type, void>::value;
  41. #endif
  42. }} // namespace boost::callable_traits
  43. //->
  44. /*`
  45. [heading Constraints]
  46. * none
  47. [heading Behavior]
  48. * `std::false_type` is inherited by `has_void_return<T>` and is aliased by `typename has_void_return<T>::type`, except when one of the following criteria is met, in which case `std::true_type` would be similarly inherited and aliased:
  49. * `T` is a function, function pointer, or function reference where the function's return type is `void`.
  50. * `T` is a pointer to a member function whose return type is `void`.
  51. * `T` is a function object with a non-overloaded `operator()`, where the `operator()` function returns `void`.
  52. * On compilers that support variable templates, `has_void_return_v<T>` is equivalent to `has_void_return<T>::value`.
  53. [heading Input/Output Examples]
  54. [table
  55. [[`T`] [`has_void_return_v<T>`]]
  56. [[`void()`] [`true`]]
  57. [[`void(int) const`] [`true`]]
  58. [[`void(* const &)()`] [`true`]]
  59. [[`void(&)()`] [`true`]]
  60. [[`void(foo::*)() const`] [`true`]]
  61. [[`int(*)()`] [`false`]]
  62. [[`int(*&)()`] [`false`]]
  63. [[`int`] [`false`]]
  64. [[`int foo::*`] [`false`]]
  65. [[`void* foo::*`] [`false`]]
  66. ]
  67. [heading Example Program]
  68. [import ../example/has_void_return.cpp]
  69. [has_void_return]
  70. [endsect]
  71. */
  72. //]
  73. #endif