Clementine
execute.hpp
1 //
2 // execution/execute.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_EXECUTE_HPP
12 #define ASIO_EXECUTION_EXECUTE_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/execution/detail/as_invocable.hpp"
21 #include "asio/execution/detail/as_receiver.hpp"
22 #include "asio/traits/execute_member.hpp"
23 #include "asio/traits/execute_free.hpp"
24 
25 #include "asio/detail/push_options.hpp"
26 
27 #if defined(GENERATING_DOCUMENTATION)
28 
29 namespace asio {
30 namespace execution {
31 
33 
54 inline constexpr unspecified execute = unspecified;
55 
57 
62 template <typename T, typename F>
63 struct can_execute :
64  integral_constant<bool, automatically_determined>
65 {
66 };
67 
68 } // namespace execution
69 } // namespace asio
70 
71 #else // defined(GENERATING_DOCUMENTATION)
72 
73 namespace asio {
74 namespace execution {
75 
76 template <typename T, typename R>
77 struct is_sender_to;
78 
79 namespace detail {
80 
81 template <typename S, typename R>
82 void submit_helper(ASIO_MOVE_ARG(S) s, ASIO_MOVE_ARG(R) r);
83 
84 } // namespace detail
85 } // namespace execution
86 } // namespace asio
87 namespace asio_execution_execute_fn {
88 
89 using asio::conditional;
90 using asio::decay;
91 using asio::declval;
92 using asio::enable_if;
96 using asio::false_type;
97 using asio::result_of;
100 using asio::true_type;
101 
102 void execute();
103 
104 enum overload_type
105 {
106  call_member,
107  call_free,
108  adapter,
109  ill_formed
110 };
111 
112 template <typename T, typename F, typename = void>
114 {
115  ASIO_STATIC_CONSTEXPR(overload_type, overload = ill_formed);
116 };
117 
118 template <typename T, typename F>
119 struct call_traits<T, void(F),
120  typename enable_if<
121  (
122  execute_member<T, F>::is_valid
123  )
124  >::type> :
125  execute_member<T, F>
126 {
127  ASIO_STATIC_CONSTEXPR(overload_type, overload = call_member);
128 };
129 
130 template <typename T, typename F>
131 struct call_traits<T, void(F),
132  typename enable_if<
133  (
134  !execute_member<T, F>::is_valid
135  &&
136  execute_free<T, F>::is_valid
137  )
138  >::type> :
139  execute_free<T, F>
140 {
141  ASIO_STATIC_CONSTEXPR(overload_type, overload = call_free);
142 };
143 
144 template <typename T, typename F>
145 struct call_traits<T, void(F),
146  typename enable_if<
147  (
148  !execute_member<T, F>::is_valid
149  &&
150  !execute_free<T, F>::is_valid
151  &&
152  conditional<true, true_type,
153  typename result_of<typename decay<F>::type&()>::type
154  >::type::value
155  &&
156  conditional<
157  !is_as_invocable<
158  typename decay<F>::type
159  >::value,
160  is_sender_to<
161  T,
162  as_receiver<typename decay<F>::type, T>
163  >,
164  false_type
165  >::type::value
166  )
167  >::type>
168 {
169  ASIO_STATIC_CONSTEXPR(overload_type, overload = adapter);
170  ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
171  ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
172  typedef void result_type;
173 };
174 
175 struct impl
176 {
177  template <typename T, typename F>
178  ASIO_CONSTEXPR typename enable_if<
179  call_traits<T, void(F)>::overload == call_member,
181  >::type
182  operator()(
183  ASIO_MOVE_ARG(T) t,
184  ASIO_MOVE_ARG(F) f) const
185  ASIO_NOEXCEPT_IF((
186  call_traits<T, void(F)>::is_noexcept))
187  {
188  return ASIO_MOVE_CAST(T)(t).execute(ASIO_MOVE_CAST(F)(f));
189  }
190 
191  template <typename T, typename F>
192  ASIO_CONSTEXPR typename enable_if<
193  call_traits<T, void(F)>::overload == call_free,
195  >::type
196  operator()(
197  ASIO_MOVE_ARG(T) t,
198  ASIO_MOVE_ARG(F) f) const
199  ASIO_NOEXCEPT_IF((
200  call_traits<T, void(F)>::is_noexcept))
201  {
202  return execute(ASIO_MOVE_CAST(T)(t), ASIO_MOVE_CAST(F)(f));
203  }
204 
205  template <typename T, typename F>
206  ASIO_CONSTEXPR typename enable_if<
207  call_traits<T, void(F)>::overload == adapter,
209  >::type
210  operator()(
211  ASIO_MOVE_ARG(T) t,
212  ASIO_MOVE_ARG(F) f) const
213  ASIO_NOEXCEPT_IF((
214  call_traits<T, void(F)>::is_noexcept))
215  {
216  return asio::execution::detail::submit_helper(
217  ASIO_MOVE_CAST(T)(t),
218  as_receiver<typename decay<F>::type, T>(
219  ASIO_MOVE_CAST(F)(f), 0));
220  }
221 };
222 
223 template <typename T = impl>
225 {
226  static const T instance;
227 };
228 
229 template <typename T>
230 const T static_instance<T>::instance = {};
231 
232 } // namespace asio_execution_execute_fn
233 namespace asio {
234 namespace execution {
235 namespace {
236 
237 static ASIO_CONSTEXPR const asio_execution_execute_fn::impl&
239 
240 } // namespace
241 
242 template <typename T, typename F>
243 struct can_execute :
244  integral_constant<bool,
245  asio_execution_execute_fn::call_traits<T, void(F)>::overload !=
246  asio_execution_execute_fn::ill_formed>
247 {
248 };
249 
250 #if defined(ASIO_HAS_VARIABLE_TEMPLATES)
251 
252 template <typename T, typename F>
253 constexpr bool can_execute_v = can_execute<T, F>::value;
254 
255 #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
256 
257 } // namespace execution
258 } // namespace asio
259 
260 #endif // defined(GENERATING_DOCUMENTATION)
261 
262 #include "asio/detail/pop_options.hpp"
263 
264 #endif // ASIO_EXECUTION_EXECUTE_HPP
Definition: blocking.hpp:208
Definition: execute_free.hpp:38
Definition: execute.hpp:243
Definition: execute.hpp:113
Definition: execute.hpp:175
Definition: as_receiver.hpp:31
Definition: execute_member.hpp:38
Definition: chrono.h:284
Definition: type_traits.hpp:97
Definition: as_invocable.hpp:137
Definition: handler_work.hpp:37
Definition: execute.hpp:87
The is_sender_to trait detects whether a type T satisfies the execution::sender_to concept for some r...
Definition: execute.hpp:77
Definition: any_io_executor.hpp:28