2 // execution/set_value.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_SET_VALUE_HPP
12 #define BOOST_ASIO_EXECUTION_SET_VALUE_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/detail/variadic_templates.hpp>
21 #include <boost/asio/traits/set_value_member.hpp>
22 #include <boost/asio/traits/set_value_free.hpp>
24 #include <boost/asio/detail/push_options.hpp>
26 #if defined(GENERATING_DOCUMENTATION)
32 /// A customisation point that delivers a value to a receiver.
34 * The name <tt>execution::set_value</tt> denotes a customisation point object.
35 * The expression <tt>execution::set_value(R, Vs...)</tt> for some
36 * subexpressions <tt>R</tt> and <tt>Vs...</tt> is expression-equivalent to:
38 * @li <tt>R.set_value(Vs...)</tt>, if that expression is valid. If the
39 * function selected does not send the value(s) <tt>Vs...</tt> to the receiver
40 * <tt>R</tt>'s value channel, the program is ill-formed with no diagnostic
43 * @li Otherwise, <tt>set_value(R, Vs...)</tt>, if that expression is valid,
44 * with overload resolution performed in a context that includes the
45 * declaration <tt>void set_value();</tt> and that does not include a
46 * declaration of <tt>execution::set_value</tt>. If the function selected by
47 * overload resolution does not send the value(s) <tt>Vs...</tt> to the
48 * receiver <tt>R</tt>'s value channel, the program is ill-formed with no
49 * diagnostic required.
51 * @li Otherwise, <tt>execution::set_value(R, Vs...)</tt> is ill-formed.
53 inline constexpr unspecified set_value = unspecified;
55 /// A type trait that determines whether a @c set_value expression is
58 * Class template @c can_set_value is a trait that is derived from
59 * @c true_type if the expression <tt>execution::set_value(std::declval<R>(),
60 * std::declval<Vs>()...)</tt> is well formed; otherwise @c false_type.
62 template <typename R, typename... Vs>
63 struct can_set_value :
64 integral_constant<bool, automatically_determined>
68 } // namespace execution
72 #else // defined(GENERATING_DOCUMENTATION)
74 namespace asio_execution_set_value_fn {
76 using boost::asio::decay;
77 using boost::asio::declval;
78 using boost::asio::enable_if;
79 using boost::asio::traits::set_value_free;
80 using boost::asio::traits::set_value_member;
91 template <typename R, typename Vs, typename = void>
94 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = ill_formed);
95 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
96 typedef void result_type;
99 template <typename R, typename Vs>
100 struct call_traits<R, Vs,
103 set_value_member<R, Vs>::is_valid
106 set_value_member<R, Vs>
108 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_member);
111 template <typename R, typename Vs>
112 struct call_traits<R, Vs,
115 !set_value_member<R, Vs>::is_valid
117 set_value_free<R, Vs>::is_valid
120 set_value_free<R, Vs>
122 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_free);
127 #if defined(BOOST_ASIO_HAS_MOVE)
129 #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
131 template <typename R, typename... Vs>
132 BOOST_ASIO_CONSTEXPR typename enable_if<
133 call_traits<R, void(Vs...)>::overload == call_member,
134 typename call_traits<R, void(Vs...)>::result_type
136 operator()(R&& r, Vs&&... v) const
137 BOOST_ASIO_NOEXCEPT_IF((
138 call_traits<R, void(Vs...)>::is_noexcept))
140 return BOOST_ASIO_MOVE_CAST(R)(r).set_value(BOOST_ASIO_MOVE_CAST(Vs)(v)...);
143 template <typename R, typename... Vs>
144 BOOST_ASIO_CONSTEXPR typename enable_if<
145 call_traits<R, void(Vs...)>::overload == call_free,
146 typename call_traits<R, void(Vs...)>::result_type
148 operator()(R&& r, Vs&&... v) const
149 BOOST_ASIO_NOEXCEPT_IF((
150 call_traits<R, void(Vs...)>::is_noexcept))
152 return set_value(BOOST_ASIO_MOVE_CAST(R)(r),
153 BOOST_ASIO_MOVE_CAST(Vs)(v)...);
156 #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
158 template <typename R>
159 BOOST_ASIO_CONSTEXPR typename enable_if<
160 call_traits<R, void()>::overload == call_member,
161 typename call_traits<R, void()>::result_type
163 operator()(R&& r) const
164 BOOST_ASIO_NOEXCEPT_IF((
165 call_traits<R, void()>::is_noexcept))
167 return BOOST_ASIO_MOVE_CAST(R)(r).set_value();
170 template <typename R>
171 BOOST_ASIO_CONSTEXPR typename enable_if<
172 call_traits<R, void()>::overload == call_free,
173 typename call_traits<R, void()>::result_type
175 operator()(R&& r) const
176 BOOST_ASIO_NOEXCEPT_IF((
177 call_traits<R, void()>::is_noexcept))
179 return set_value(BOOST_ASIO_MOVE_CAST(R)(r));
182 #define BOOST_ASIO_PRIVATE_SET_VALUE_CALL_DEF(n) \
183 template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
184 BOOST_ASIO_CONSTEXPR typename enable_if< \
186 void(BOOST_ASIO_VARIADIC_TARGS(n))>::overload == call_member, \
187 typename call_traits<R, void(BOOST_ASIO_VARIADIC_TARGS(n))>::result_type \
189 operator()(R&& r, BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) const \
190 BOOST_ASIO_NOEXCEPT_IF(( \
191 call_traits<R, void(BOOST_ASIO_VARIADIC_TARGS(n))>::is_noexcept)) \
193 return BOOST_ASIO_MOVE_CAST(R)(r).set_value( \
194 BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
197 template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
198 BOOST_ASIO_CONSTEXPR typename enable_if< \
199 call_traits<R, void(BOOST_ASIO_VARIADIC_TARGS(n))>::overload == call_free, \
200 typename call_traits<R, void(BOOST_ASIO_VARIADIC_TARGS(n))>::result_type \
202 operator()(R&& r, BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) const \
203 BOOST_ASIO_NOEXCEPT_IF(( \
204 call_traits<R, void(BOOST_ASIO_VARIADIC_TARGS(n))>::is_noexcept)) \
206 return set_value(BOOST_ASIO_MOVE_CAST(R)(r), \
207 BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
210 BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SET_VALUE_CALL_DEF)
211 #undef BOOST_ASIO_PRIVATE_SET_VALUE_CALL_DEF
213 #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
215 #else // defined(BOOST_ASIO_HAS_MOVE)
217 #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
219 template <typename R, typename... Vs>
220 BOOST_ASIO_CONSTEXPR typename enable_if<
221 call_traits<R&, void(const Vs&...)>::overload == call_member,
222 typename call_traits<R&, void(const Vs&...)>::result_type
224 operator()(R& r, const Vs&... v) const
225 BOOST_ASIO_NOEXCEPT_IF((
226 call_traits<R&, void(const Vs&...)>::is_noexcept))
228 return r.set_value(v...);
231 template <typename R, typename... Vs>
232 BOOST_ASIO_CONSTEXPR typename enable_if<
233 call_traits<const R&, void(const Vs&...)>::overload == call_member,
234 typename call_traits<const R&, void(const Vs&...)>::result_type
236 operator()(const R& r, const Vs&... v) const
237 BOOST_ASIO_NOEXCEPT_IF((
238 call_traits<const R&, void(const Vs&...)>::is_noexcept))
240 return r.set_value(v...);
243 template <typename R, typename... Vs>
244 BOOST_ASIO_CONSTEXPR typename enable_if<
245 call_traits<R&, void(const Vs&...)>::overload == call_free,
246 typename call_traits<R&, void(const Vs&...)>::result_type
248 operator()(R& r, const Vs&... v) const
249 BOOST_ASIO_NOEXCEPT_IF((
250 call_traits<R&, void(const Vs&...)>::is_noexcept))
252 return set_value(r, v...);
255 template <typename R, typename... Vs>
256 BOOST_ASIO_CONSTEXPR typename enable_if<
257 call_traits<const R&, void(const Vs&...)>::overload == call_free,
258 typename call_traits<const R&, void(const Vs&...)>::result_type
260 operator()(const R& r, const Vs&... v) const
261 BOOST_ASIO_NOEXCEPT_IF((
262 call_traits<const R&, void(const Vs&...)>::is_noexcept))
264 return set_value(r, v...);
267 #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
269 template <typename R>
270 BOOST_ASIO_CONSTEXPR typename enable_if<
271 call_traits<R&, void()>::overload == call_member,
272 typename call_traits<R&, void()>::result_type
274 operator()(R& r) const
275 BOOST_ASIO_NOEXCEPT_IF((
276 call_traits<R&, void()>::is_noexcept))
278 return r.set_value();
281 template <typename R>
282 BOOST_ASIO_CONSTEXPR typename enable_if<
283 call_traits<const R&, void()>::overload == call_member,
284 typename call_traits<const R&, void()>::result_type
286 operator()(const R& r) const
287 BOOST_ASIO_NOEXCEPT_IF((
288 call_traits<const R&, void()>::is_noexcept))
290 return r.set_value();
293 template <typename R>
294 BOOST_ASIO_CONSTEXPR typename enable_if<
295 call_traits<R&, void()>::overload == call_free,
296 typename call_traits<R&, void()>::result_type
298 operator()(R& r) const
299 BOOST_ASIO_NOEXCEPT_IF((
300 call_traits<R&, void()>::is_noexcept))
305 template <typename R>
306 BOOST_ASIO_CONSTEXPR typename enable_if<
307 call_traits<const R&, void()>::overload == call_free,
308 typename call_traits<const R&, void()>::result_type
310 operator()(const R& r) const
311 BOOST_ASIO_NOEXCEPT_IF((
312 call_traits<const R&, void()>::is_noexcept))
317 #define BOOST_ASIO_PRIVATE_SET_VALUE_CALL_DEF(n) \
318 template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
319 BOOST_ASIO_CONSTEXPR typename enable_if< \
321 void(BOOST_ASIO_VARIADIC_TARGS(n))>::overload == call_member, \
322 typename call_traits<R&, void(BOOST_ASIO_VARIADIC_TARGS(n))>::result_type \
324 operator()(R& r, BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) const \
325 BOOST_ASIO_NOEXCEPT_IF(( \
326 call_traits<R&, void(BOOST_ASIO_VARIADIC_TARGS(n))>::is_noexcept)) \
328 return r.set_value(BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
331 template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
332 BOOST_ASIO_CONSTEXPR typename enable_if< \
333 call_traits<const R&, \
334 void(BOOST_ASIO_VARIADIC_TARGS(n))>::overload == call_member, \
335 typename call_traits<const R&, \
336 void(BOOST_ASIO_VARIADIC_TARGS(n))>::result_type \
338 operator()(const R& r, BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) const \
339 BOOST_ASIO_NOEXCEPT_IF(( \
340 call_traits<const R&, void(BOOST_ASIO_VARIADIC_TARGS(n))>::is_noexcept)) \
342 return r.set_value(BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
345 template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
346 BOOST_ASIO_CONSTEXPR typename enable_if< \
348 void(BOOST_ASIO_VARIADIC_TARGS(n))>::overload == call_free, \
349 typename call_traits<R&, void(BOOST_ASIO_VARIADIC_TARGS(n))>::result_type \
351 operator()(R& r, BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) const \
352 BOOST_ASIO_NOEXCEPT_IF(( \
353 call_traits<R&, void(BOOST_ASIO_VARIADIC_TARGS(n))>::is_noexcept)) \
355 return set_value(r, BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
358 template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
359 BOOST_ASIO_CONSTEXPR typename enable_if< \
360 call_traits<const R&, \
361 void(BOOST_ASIO_VARIADIC_TARGS(n))>::overload == call_free, \
362 typename call_traits<const R&, \
363 void(BOOST_ASIO_VARIADIC_TARGS(n))>::result_type \
365 operator()(const R& r, BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) const \
366 BOOST_ASIO_NOEXCEPT_IF(( \
367 call_traits<const R&, void(BOOST_ASIO_VARIADIC_TARGS(n))>::is_noexcept)) \
369 return set_value(r, BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
372 BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SET_VALUE_CALL_DEF)
373 #undef BOOST_ASIO_PRIVATE_SET_VALUE_CALL_DEF
375 #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
377 #endif // defined(BOOST_ASIO_HAS_MOVE)
380 template <typename T = impl>
381 struct static_instance
383 static const T instance;
386 template <typename T>
387 const T static_instance<T>::instance = {};
389 } // namespace asio_execution_set_value_fn
392 namespace execution {
395 static BOOST_ASIO_CONSTEXPR const asio_execution_set_value_fn::impl&
396 set_value = asio_execution_set_value_fn::static_instance<>::instance;
400 #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
402 template <typename R, typename... Vs>
403 struct can_set_value :
404 integral_constant<bool,
405 asio_execution_set_value_fn::call_traits<R, void(Vs...)>::overload !=
406 asio_execution_set_value_fn::ill_formed>
410 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
412 template <typename R, typename... Vs>
413 constexpr bool can_set_value_v = can_set_value<R, Vs...>::value;
415 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
417 template <typename R, typename... Vs>
418 struct is_nothrow_set_value :
419 integral_constant<bool,
420 asio_execution_set_value_fn::call_traits<R, void(Vs...)>::is_noexcept>
424 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
426 template <typename R, typename... Vs>
427 constexpr bool is_nothrow_set_value_v
428 = is_nothrow_set_value<R, Vs...>::value;
430 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
432 #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
434 template <typename R, typename = void,
435 typename = void, typename = void, typename = void, typename = void,
436 typename = void, typename = void, typename = void, typename = void>
437 struct can_set_value;
439 template <typename R, typename = void,
440 typename = void, typename = void, typename = void, typename = void,
441 typename = void, typename = void, typename = void, typename = void>
442 struct is_nothrow_set_value;
444 template <typename R>
445 struct can_set_value<R> :
446 integral_constant<bool,
447 asio_execution_set_value_fn::call_traits<R, void()>::overload !=
448 asio_execution_set_value_fn::ill_formed>
452 template <typename R>
453 struct is_nothrow_set_value<R> :
454 integral_constant<bool,
455 asio_execution_set_value_fn::call_traits<R, void()>::is_noexcept>
459 #define BOOST_ASIO_PRIVATE_SET_VALUE_TRAITS_DEF(n) \
460 template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
461 struct can_set_value<R, BOOST_ASIO_VARIADIC_TARGS(n)> : \
462 integral_constant<bool, \
463 asio_execution_set_value_fn::call_traits<R, \
464 void(BOOST_ASIO_VARIADIC_TARGS(n))>::overload != \
465 asio_execution_set_value_fn::ill_formed> \
469 template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
470 struct is_nothrow_set_value<R, BOOST_ASIO_VARIADIC_TARGS(n)> : \
471 integral_constant<bool, \
472 asio_execution_set_value_fn::call_traits<R, \
473 void(BOOST_ASIO_VARIADIC_TARGS(n))>::is_noexcept> \
477 BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SET_VALUE_TRAITS_DEF)
478 #undef BOOST_ASIO_PRIVATE_SET_VALUE_TRAITS_DEF
480 #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
482 } // namespace execution
486 #endif // defined(GENERATING_DOCUMENTATION)
488 #include <boost/asio/detail/pop_options.hpp>
490 #endif // BOOST_ASIO_EXECUTION_SET_VALUE_HPP