2 // execution/bulk_execute.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_EXECUTION_BULK_EXECUTE_HPP
12 #define BOOST_ASIO_EXECUTION_BULK_EXECUTE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/type_traits.hpp>
20 #include <boost/asio/execution/bulk_guarantee.hpp>
21 #include <boost/asio/execution/detail/bulk_sender.hpp>
22 #include <boost/asio/execution/executor.hpp>
23 #include <boost/asio/execution/sender.hpp>
24 #include <boost/asio/traits/bulk_execute_member.hpp>
25 #include <boost/asio/traits/bulk_execute_free.hpp>
27 #include <boost/asio/detail/push_options.hpp>
29 #if defined(GENERATING_DOCUMENTATION)
35 /// A customisation point that creates a bulk sender.
37 * The name <tt>execution::bulk_execute</tt> denotes a customisation point
38 * object. If <tt>is_convertible_v<N, size_t></tt> is true, then the expression
39 * <tt>execution::bulk_execute(S, F, N)</tt> for some subexpressions
40 * <tt>S</tt>, <tt>F</tt>, and <tt>N</tt> is expression-equivalent to:
42 * @li <tt>S.bulk_execute(F, N)</tt>, if that expression is valid. If the
43 * function selected does not execute <tt>N</tt> invocations of the function
44 * object <tt>F</tt> on the executor <tt>S</tt> in bulk with forward progress
45 * guarantee <tt>boost::asio::query(S, execution::bulk_guarantee)</tt>, and
46 * the result of that function does not model <tt>sender<void></tt>, the
47 * program is ill-formed with no diagnostic required.
49 * @li Otherwise, <tt>bulk_execute(S, F, N)</tt>, if that expression is valid,
50 * with overload resolution performed in a context that includes the
51 * declaration <tt>void bulk_execute();</tt> and that does not include a
52 * declaration of <tt>execution::bulk_execute</tt>. If the function selected
53 * by overload resolution does not execute <tt>N</tt> invocations of the
54 * function object <tt>F</tt> on the executor <tt>S</tt> in bulk with forward
55 * progress guarantee <tt>boost::asio::query(E,
56 * execution::bulk_guarantee)</tt>, and the result of that function does not
57 * model <tt>sender<void></tt>, the program is ill-formed with no diagnostic
60 * @li Otherwise, if the types <tt>F</tt> and
61 * <tt>executor_index_t<remove_cvref_t<S>></tt> model <tt>invocable</tt> and
62 * if <tt>boost::asio::query(S, execution::bulk_guarantee)</tt> equals
63 * <tt>execution::bulk_guarantee.unsequenced</tt>, then
65 * - Evaluates <tt>DECAY_COPY(std::forward<decltype(F)>(F))</tt> on the
66 * calling thread to create a function object <tt>cf</tt>. [Note:
67 * Additional copies of <tt>cf</tt> may subsequently be created. --end
70 * - For each value of <tt>i</tt> in <tt>N</tt>, <tt>cf(i)</tt> (or copy of
71 * <tt>cf</tt>)) will be invoked at most once by an execution agent that is
72 * unique for each value of <tt>i</tt>.
74 * - May block pending completion of one or more invocations of <tt>cf</tt>.
76 * - Synchronizes with (C++Std [intro.multithread]) the invocations of
79 * @li Otherwise, <tt>execution::bulk_execute(S, F, N)</tt> is ill-formed.
81 inline constexpr unspecified bulk_execute = unspecified;
83 /// A type trait that determines whether a @c bulk_execute expression is
86 * Class template @c can_bulk_execute is a trait that is derived from @c
87 * true_type if the expression <tt>execution::bulk_execute(std::declval<S>(),
88 * std::declval<F>(), std::declval<N>)</tt> is well formed; otherwise @c
91 template <typename S, typename F, typename N>
92 struct can_bulk_execute :
93 integral_constant<bool, automatically_determined>
97 } // namespace execution
101 #else // defined(GENERATING_DOCUMENTATION)
103 namespace boost_asio_execution_bulk_execute_fn {
105 using boost::asio::declval;
106 using boost::asio::enable_if;
107 using boost::asio::execution::bulk_guarantee_t;
108 using boost::asio::execution::detail::bulk_sender;
109 using boost::asio::execution::executor_index;
110 using boost::asio::execution::is_sender;
111 using boost::asio::is_convertible;
112 using boost::asio::is_same;
113 using boost::asio::remove_cvref;
114 using boost::asio::result_of;
115 using boost::asio::traits::bulk_execute_free;
116 using boost::asio::traits::bulk_execute_member;
117 using boost::asio::traits::static_require;
129 template <typename S, typename Args, typename = void, typename = void,
130 typename = void, typename = void, typename = void, typename = void>
133 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = ill_formed);
134 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
135 typedef void result_type;
138 template <typename S, typename F, typename N>
139 struct call_traits<S, void(F, N),
141 is_convertible<N, std::size_t>::value
144 bulk_execute_member<S, F, N>::is_valid
148 typename bulk_execute_member<S, F, N>::result_type
151 bulk_execute_member<S, F, N>
153 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_member);
156 template <typename S, typename F, typename N>
157 struct call_traits<S, void(F, N),
159 is_convertible<N, std::size_t>::value
162 !bulk_execute_member<S, F, N>::is_valid
165 bulk_execute_free<S, F, N>::is_valid
169 typename bulk_execute_free<S, F, N>::result_type
172 bulk_execute_free<S, F, N>
174 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_free);
177 template <typename S, typename F, typename N>
178 struct call_traits<S, void(F, N),
180 is_convertible<N, std::size_t>::value
183 !bulk_execute_member<S, F, N>::is_valid
186 !bulk_execute_free<S, F, N>::is_valid
194 F(typename executor_index<typename remove_cvref<S>::type>::type)
197 F(typename executor_index<typename remove_cvref<S>::type>::type)
202 static_require<S, bulk_guarantee_t::unsequenced_t>::is_valid
205 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = adapter);
206 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
207 typedef bulk_sender<S, F, N> result_type;
212 #if defined(BOOST_ASIO_HAS_MOVE)
213 template <typename S, typename F, typename N>
214 BOOST_ASIO_CONSTEXPR typename enable_if<
215 call_traits<S, void(F, N)>::overload == call_member,
216 typename call_traits<S, void(F, N)>::result_type
218 operator()(S&& s, F&& f, N&& n) const
219 BOOST_ASIO_NOEXCEPT_IF((
220 call_traits<S, void(F, N)>::is_noexcept))
222 return BOOST_ASIO_MOVE_CAST(S)(s).bulk_execute(
223 BOOST_ASIO_MOVE_CAST(F)(f), BOOST_ASIO_MOVE_CAST(N)(n));
226 template <typename S, typename F, typename N>
227 BOOST_ASIO_CONSTEXPR typename enable_if<
228 call_traits<S, void(F, N)>::overload == call_free,
229 typename call_traits<S, void(F, N)>::result_type
231 operator()(S&& s, F&& f, N&& n) const
232 BOOST_ASIO_NOEXCEPT_IF((
233 call_traits<S, void(F, N)>::is_noexcept))
235 return bulk_execute(BOOST_ASIO_MOVE_CAST(S)(s),
236 BOOST_ASIO_MOVE_CAST(F)(f), BOOST_ASIO_MOVE_CAST(N)(n));
239 template <typename S, typename F, typename N>
240 BOOST_ASIO_CONSTEXPR typename enable_if<
241 call_traits<S, void(F, N)>::overload == adapter,
242 typename call_traits<S, void(F, N)>::result_type
244 operator()(S&& s, F&& f, N&& n) const
245 BOOST_ASIO_NOEXCEPT_IF((
246 call_traits<S, void(F, N)>::is_noexcept))
248 return typename call_traits<S, void(F, N)>::result_type(
249 BOOST_ASIO_MOVE_CAST(S)(s), BOOST_ASIO_MOVE_CAST(F)(f),
250 BOOST_ASIO_MOVE_CAST(N)(n));
252 #else // defined(BOOST_ASIO_HAS_MOVE)
253 template <typename S, typename F, typename N>
254 BOOST_ASIO_CONSTEXPR typename enable_if<
255 call_traits<S, void(const F&, const N&)>::overload == call_member,
256 typename call_traits<S, void(const F&, const N&)>::result_type
258 operator()(S& s, const F& f, const N& n) const
259 BOOST_ASIO_NOEXCEPT_IF((
260 call_traits<S, void(const F&, const N&)>::is_noexcept))
262 return s.bulk_execute(BOOST_ASIO_MOVE_CAST(F)(f),
263 BOOST_ASIO_MOVE_CAST(N)(n));
266 template <typename S, typename F, typename N>
267 BOOST_ASIO_CONSTEXPR typename enable_if<
268 call_traits<S, void(const F&, const N&)>::overload == call_member,
269 typename call_traits<S, void(const F&, const N&)>::result_type
271 operator()(const S& s, const F& f, const N& n) const
272 BOOST_ASIO_NOEXCEPT_IF((
273 call_traits<S, void(const F&, const N&)>::is_noexcept))
275 return s.bulk_execute(BOOST_ASIO_MOVE_CAST(F)(f),
276 BOOST_ASIO_MOVE_CAST(N)(n));
279 template <typename S, typename F, typename N>
280 BOOST_ASIO_CONSTEXPR typename enable_if<
281 call_traits<S, void(const F&, const N&)>::overload == call_free,
282 typename call_traits<S, void(const F&, const N&)>::result_type
284 operator()(S& s, const F& f, const N& n) const
285 BOOST_ASIO_NOEXCEPT_IF((
286 call_traits<S, void(const F&, const N&)>::is_noexcept))
288 return bulk_execute(s, BOOST_ASIO_MOVE_CAST(F)(f),
289 BOOST_ASIO_MOVE_CAST(N)(n));
292 template <typename S, typename F, typename N>
293 BOOST_ASIO_CONSTEXPR typename enable_if<
294 call_traits<S, void(const F&, const N&)>::overload == call_free,
295 typename call_traits<S, void(const F&, const N&)>::result_type
297 operator()(const S& s, const F& f, const N& n) const
298 BOOST_ASIO_NOEXCEPT_IF((
299 call_traits<S, void(const F&, const N&)>::is_noexcept))
301 return bulk_execute(s, BOOST_ASIO_MOVE_CAST(F)(f),
302 BOOST_ASIO_MOVE_CAST(N)(n));
305 template <typename S, typename F, typename N>
306 BOOST_ASIO_CONSTEXPR typename enable_if<
307 call_traits<S, void(const F&, const N&)>::overload == adapter,
308 typename call_traits<S, void(const F&, const N&)>::result_type
310 operator()(S& s, const F& f, const N& n) const
311 BOOST_ASIO_NOEXCEPT_IF((
312 call_traits<S, void(const F&, const N&)>::is_noexcept))
314 return typename call_traits<S, void(const F&, const N&)>::result_type(
315 s, BOOST_ASIO_MOVE_CAST(F)(f), BOOST_ASIO_MOVE_CAST(N)(n));
318 template <typename S, typename F, typename N>
319 BOOST_ASIO_CONSTEXPR typename enable_if<
320 call_traits<S, void(const F&, const N&)>::overload == adapter,
321 typename call_traits<S, void(const F&, const N&)>::result_type
323 operator()(const S& s, const F& f, const N& n) const
324 BOOST_ASIO_NOEXCEPT_IF((
325 call_traits<S, void(const F&, const N&)>::is_noexcept))
327 return typename call_traits<S, void(const F&, const N&)>::result_type(
328 s, BOOST_ASIO_MOVE_CAST(F)(f), BOOST_ASIO_MOVE_CAST(N)(n));
330 #endif // defined(BOOST_ASIO_HAS_MOVE)
333 template <typename T = impl>
334 struct static_instance
336 static const T instance;
339 template <typename T>
340 const T static_instance<T>::instance = {};
342 } // namespace boost_asio_execution_bulk_execute_fn
345 namespace execution {
348 static BOOST_ASIO_CONSTEXPR
349 const boost_asio_execution_bulk_execute_fn::impl& bulk_execute =
350 boost_asio_execution_bulk_execute_fn::static_instance<>::instance;
354 template <typename S, typename F, typename N>
355 struct can_bulk_execute :
356 integral_constant<bool,
357 boost_asio_execution_bulk_execute_fn::call_traits<
358 S, void(F, N)>::overload !=
359 boost_asio_execution_bulk_execute_fn::ill_formed>
363 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
365 template <typename S, typename F, typename N>
366 constexpr bool can_bulk_execute_v = can_bulk_execute<S, F, N>::value;
368 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
370 template <typename S, typename F, typename N>
371 struct is_nothrow_bulk_execute :
372 integral_constant<bool,
373 boost_asio_execution_bulk_execute_fn::call_traits<
374 S, void(F, N)>::is_noexcept>
378 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
380 template <typename S, typename F, typename N>
381 constexpr bool is_nothrow_bulk_execute_v
382 = is_nothrow_bulk_execute<S, F, N>::value;
384 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
386 template <typename S, typename F, typename N>
387 struct bulk_execute_result
389 typedef typename boost_asio_execution_bulk_execute_fn::call_traits<
390 S, void(F, N)>::result_type type;
393 } // namespace execution
397 #endif // defined(GENERATING_DOCUMENTATION)
399 #include <boost/asio/detail/pop_options.hpp>
401 #endif // BOOST_ASIO_EXECUTION_BULK_EXECUTE_HPP