execute_member.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // traits/execute_member.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_TRAITS_EXECUTE_MEMBER_HPP
  11. #define BOOST_ASIO_TRAITS_EXECUTE_MEMBER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/type_traits.hpp>
  17. #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  18. # define BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT 1
  19. #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  20. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. namespace traits {
  24. template <typename T, typename F, typename = void>
  25. struct execute_member_default;
  26. template <typename T, typename F, typename = void>
  27. struct execute_member;
  28. } // namespace traits
  29. namespace detail {
  30. struct no_execute_member
  31. {
  32. static constexpr bool is_valid = false;
  33. static constexpr bool is_noexcept = false;
  34. };
  35. #if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
  36. template <typename T, typename F, typename = void>
  37. struct execute_member_trait : no_execute_member
  38. {
  39. };
  40. template <typename T, typename F>
  41. struct execute_member_trait<T, F,
  42. void_t<
  43. decltype(declval<T>().execute(declval<F>()))
  44. >>
  45. {
  46. static constexpr bool is_valid = true;
  47. using result_type = decltype(
  48. declval<T>().execute(declval<F>()));
  49. static constexpr bool is_noexcept =
  50. noexcept(declval<T>().execute(declval<F>()));
  51. };
  52. #else // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
  53. template <typename T, typename F, typename = void>
  54. struct execute_member_trait :
  55. conditional_t<
  56. is_same<T, decay_t<T>>::value
  57. && is_same<F, decay_t<F>>::value,
  58. no_execute_member,
  59. traits::execute_member<
  60. decay_t<T>,
  61. decay_t<F>>
  62. >
  63. {
  64. };
  65. #endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
  66. } // namespace detail
  67. namespace traits {
  68. template <typename T, typename F, typename>
  69. struct execute_member_default :
  70. detail::execute_member_trait<T, F>
  71. {
  72. };
  73. template <typename T, typename F, typename>
  74. struct execute_member :
  75. execute_member_default<T, F>
  76. {
  77. };
  78. } // namespace traits
  79. } // namespace asio
  80. } // namespace boost
  81. #include <boost/asio/detail/pop_options.hpp>
  82. #endif // BOOST_ASIO_TRAITS_EXECUTE_MEMBER_HPP