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