as_receiver.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // execution/detail/as_receiver.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2022 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 ASIO_EXECUTION_DETAIL_AS_RECEIVER_HPP
  11. #define ASIO_EXECUTION_DETAIL_AS_RECEIVER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/detail/type_traits.hpp"
  17. #include "asio/traits/set_done_member.hpp"
  18. #include "asio/traits/set_error_member.hpp"
  19. #include "asio/traits/set_value_member.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace execution {
  23. namespace detail {
  24. template <typename Function, typename>
  25. struct as_receiver
  26. {
  27. Function f_;
  28. template <typename F>
  29. explicit as_receiver(ASIO_MOVE_ARG(F) f, int)
  30. : f_(ASIO_MOVE_CAST(F)(f))
  31. {
  32. }
  33. #if defined(ASIO_MSVC) && defined(ASIO_HAS_MOVE)
  34. as_receiver(as_receiver&& other)
  35. : f_(ASIO_MOVE_CAST(Function)(other.f_))
  36. {
  37. }
  38. #endif // defined(ASIO_MSVC) && defined(ASIO_HAS_MOVE)
  39. void set_value()
  40. ASIO_NOEXCEPT_IF(noexcept(declval<Function&>()()))
  41. {
  42. f_();
  43. }
  44. template <typename E>
  45. void set_error(E) ASIO_NOEXCEPT
  46. {
  47. std::terminate();
  48. }
  49. void set_done() ASIO_NOEXCEPT
  50. {
  51. }
  52. };
  53. template <typename T>
  54. struct is_as_receiver : false_type
  55. {
  56. };
  57. template <typename Function, typename T>
  58. struct is_as_receiver<as_receiver<Function, T> > : true_type
  59. {
  60. };
  61. } // namespace detail
  62. } // namespace execution
  63. namespace traits {
  64. #if !defined(ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
  65. template <typename Function, typename T>
  66. struct set_value_member<
  67. asio::execution::detail::as_receiver<Function, T>, void()>
  68. {
  69. ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  70. #if defined(ASIO_HAS_NOEXCEPT)
  71. ASIO_STATIC_CONSTEXPR(bool,
  72. is_noexcept = noexcept(declval<Function&>()()));
  73. #else // defined(ASIO_HAS_NOEXCEPT)
  74. ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  75. #endif // defined(ASIO_HAS_NOEXCEPT)
  76. typedef void result_type;
  77. };
  78. #endif // !defined(ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
  79. #if !defined(ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
  80. template <typename Function, typename T, typename E>
  81. struct set_error_member<
  82. asio::execution::detail::as_receiver<Function, T>, E>
  83. {
  84. ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  85. ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  86. typedef void result_type;
  87. };
  88. #endif // !defined(ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
  89. #if !defined(ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
  90. template <typename Function, typename T>
  91. struct set_done_member<
  92. asio::execution::detail::as_receiver<Function, T> >
  93. {
  94. ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  95. ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  96. typedef void result_type;
  97. };
  98. #endif // !defined(ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
  99. } // namespace traits
  100. } // namespace asio
  101. #include "asio/detail/pop_options.hpp"
  102. #endif // ASIO_EXECUTION_DETAIL_AS_RECEIVER_HPP