2 // execution/bulk_execute.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2020 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 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>
132 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = ill_formed);
133 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
134 typedef void result_type;
137 template <typename S, typename F, typename N>
138 struct call_traits<S, void(F, N),
141 is_convertible<N, std::size_t>::value
143 bulk_execute_member<S, F, N>::is_valid
146 typename bulk_execute_member<S, F, N>::result_type
150 bulk_execute_member<S, F, N>
152 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_member);
155 template <typename S, typename F, typename N>
156 struct call_traits<S, void(F, N),
159 is_convertible<N, std::size_t>::value
161 !bulk_execute_member<S, F, N>::is_valid
163 bulk_execute_free<S, F, N>::is_valid
166 typename bulk_execute_free<S, F, N>::result_type
170 bulk_execute_free<S, F, N>
172 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_free);
175 template <typename S, typename F, typename N>
176 struct call_traits<S, void(F, N),
179 is_convertible<N, std::size_t>::value
181 !bulk_execute_member<S, F, N>::is_valid
183 !bulk_execute_free<S, F, N>::is_valid
189 F(typename executor_index<typename remove_cvref<S>::type>::type)
192 F(typename executor_index<typename remove_cvref<S>::type>::type)
196 static_require<S, bulk_guarantee_t::unsequenced_t>::is_valid
200 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = adapter);
201 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
202 typedef bulk_sender<S, F, N> result_type;
207 #if defined(BOOST_ASIO_HAS_MOVE)
208 template <typename S, typename F, typename N>
209 BOOST_ASIO_CONSTEXPR typename enable_if<
210 call_traits<S, void(F, N)>::overload == call_member,
211 typename call_traits<S, void(F, N)>::result_type
213 operator()(S&& s, F&& f, N&& n) const
214 BOOST_ASIO_NOEXCEPT_IF((
215 call_traits<S, void(F, N)>::is_noexcept))
217 return BOOST_ASIO_MOVE_CAST(S)(s).bulk_execute(
218 BOOST_ASIO_MOVE_CAST(F)(f), BOOST_ASIO_MOVE_CAST(N)(n));
221 template <typename S, typename F, typename N>
222 BOOST_ASIO_CONSTEXPR typename enable_if<
223 call_traits<S, void(F, N)>::overload == call_free,
224 typename call_traits<S, void(F, N)>::result_type
226 operator()(S&& s, F&& f, N&& n) const
227 BOOST_ASIO_NOEXCEPT_IF((
228 call_traits<S, void(F, N)>::is_noexcept))
230 return bulk_execute(BOOST_ASIO_MOVE_CAST(S)(s),
231 BOOST_ASIO_MOVE_CAST(F)(f), BOOST_ASIO_MOVE_CAST(N)(n));
234 template <typename S, typename F, typename N>
235 BOOST_ASIO_CONSTEXPR typename enable_if<
236 call_traits<S, void(F, N)>::overload == adapter,
237 typename call_traits<S, void(F, N)>::result_type
239 operator()(S&& s, F&& f, N&& n) const
240 BOOST_ASIO_NOEXCEPT_IF((
241 call_traits<S, void(F, N)>::is_noexcept))
243 return typename call_traits<S, void(F, N)>::result_type(
244 BOOST_ASIO_MOVE_CAST(S)(s), BOOST_ASIO_MOVE_CAST(F)(f),
245 BOOST_ASIO_MOVE_CAST(N)(n));
247 #else // defined(BOOST_ASIO_HAS_MOVE)
248 template <typename S, typename F, typename N>
249 BOOST_ASIO_CONSTEXPR typename enable_if<
250 call_traits<S, void(const F&, const N&)>::overload == call_member,
251 typename call_traits<S, void(const F&, const N&)>::result_type
253 operator()(S& s, const F& f, const N& n) const
254 BOOST_ASIO_NOEXCEPT_IF((
255 call_traits<S, void(const F&, const N&)>::is_noexcept))
257 return s.bulk_execute(BOOST_ASIO_MOVE_CAST(F)(f),
258 BOOST_ASIO_MOVE_CAST(N)(n));
261 template <typename S, typename F, typename N>
262 BOOST_ASIO_CONSTEXPR typename enable_if<
263 call_traits<S, void(const F&, const N&)>::overload == call_member,
264 typename call_traits<S, void(const F&, const N&)>::result_type
266 operator()(const S& s, const F& f, const N& n) const
267 BOOST_ASIO_NOEXCEPT_IF((
268 call_traits<S, void(const F&, const N&)>::is_noexcept))
270 return s.bulk_execute(BOOST_ASIO_MOVE_CAST(F)(f),
271 BOOST_ASIO_MOVE_CAST(N)(n));
274 template <typename S, typename F, typename N>
275 BOOST_ASIO_CONSTEXPR typename enable_if<
276 call_traits<S, void(const F&, const N&)>::overload == call_free,
277 typename call_traits<S, void(const F&, const N&)>::result_type
279 operator()(S& s, const F& f, const N& n) const
280 BOOST_ASIO_NOEXCEPT_IF((
281 call_traits<S, void(const F&, const N&)>::is_noexcept))
283 return bulk_execute(s, BOOST_ASIO_MOVE_CAST(F)(f),
284 BOOST_ASIO_MOVE_CAST(N)(n));
287 template <typename S, typename F, typename N>
288 BOOST_ASIO_CONSTEXPR typename enable_if<
289 call_traits<S, void(const F&, const N&)>::overload == call_free,
290 typename call_traits<S, void(const F&, const N&)>::result_type
292 operator()(const S& s, const F& f, const N& n) const
293 BOOST_ASIO_NOEXCEPT_IF((
294 call_traits<S, void(const F&, const N&)>::is_noexcept))
296 return bulk_execute(s, BOOST_ASIO_MOVE_CAST(F)(f),
297 BOOST_ASIO_MOVE_CAST(N)(n));
300 template <typename S, typename F, typename N>
301 BOOST_ASIO_CONSTEXPR typename enable_if<
302 call_traits<S, void(const F&, const N&)>::overload == adapter,
303 typename call_traits<S, void(const F&, const N&)>::result_type
305 operator()(S& s, const F& f, const N& n) const
306 BOOST_ASIO_NOEXCEPT_IF((
307 call_traits<S, void(const F&, const N&)>::is_noexcept))
309 return typename call_traits<S, void(const F&, const N&)>::result_type(
310 s, BOOST_ASIO_MOVE_CAST(F)(f), BOOST_ASIO_MOVE_CAST(N)(n));
313 template <typename S, typename F, typename N>
314 BOOST_ASIO_CONSTEXPR typename enable_if<
315 call_traits<S, void(const F&, const N&)>::overload == adapter,
316 typename call_traits<S, void(const F&, const N&)>::result_type
318 operator()(const S& s, const F& f, const N& n) const
319 BOOST_ASIO_NOEXCEPT_IF((
320 call_traits<S, void(const F&, const N&)>::is_noexcept))
322 return typename call_traits<S, void(const F&, const N&)>::result_type(
323 s, BOOST_ASIO_MOVE_CAST(F)(f), BOOST_ASIO_MOVE_CAST(N)(n));
325 #endif // defined(BOOST_ASIO_HAS_MOVE)
328 template <typename T = impl>
329 struct static_instance
331 static const T instance;
334 template <typename T>
335 const T static_instance<T>::instance = {};
337 } // namespace asio_execution_bulk_execute_fn
340 namespace execution {
343 static BOOST_ASIO_CONSTEXPR
344 const asio_execution_bulk_execute_fn::impl& bulk_execute =
345 asio_execution_bulk_execute_fn::static_instance<>::instance;
349 template <typename S, typename F, typename N>
350 struct can_bulk_execute :
351 integral_constant<bool,
352 asio_execution_bulk_execute_fn::call_traits<S, void(F, N)>::overload !=
353 asio_execution_bulk_execute_fn::ill_formed>
357 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
359 template <typename S, typename F, typename N>
360 constexpr bool can_bulk_execute_v = can_bulk_execute<S, F, N>::value;
362 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
364 template <typename S, typename F, typename N>
365 struct is_nothrow_bulk_execute :
366 integral_constant<bool,
367 asio_execution_bulk_execute_fn::call_traits<S, void(F, N)>::is_noexcept>
371 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
373 template <typename S, typename F, typename N>
374 constexpr bool is_nothrow_bulk_execute_v
375 = is_nothrow_bulk_execute<S, F, N>::value;
377 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
379 template <typename S, typename F, typename N>
380 struct bulk_execute_result
382 typedef typename asio_execution_bulk_execute_fn::call_traits<
383 S, void(F, N)>::result_type type;
386 } // namespace execution
390 #endif // defined(GENERATING_DOCUMENTATION)
392 #include <boost/asio/detail/pop_options.hpp>
394 #endif // BOOST_ASIO_EXECUTION_BULK_EXECUTE_HPP