[exec.stopped.opt] (original) (raw)
33 Execution control library [exec]
33.9 Senders [exec.snd]
33.9.12 Sender adaptors [exec.adapt]
33.9.12.13 execution​::​stopped_as_optional [exec.stopped.opt]
stopped_as_optional maps a sender's stopped completion operation into a value completion operation as a disengaged optional.
The sender's value completion operation is also converted into an optional.
The result is a sender that never completes with stopped, reporting cancellation by completing with a disengaged optional.
The name stopped_as_optional denotes a pipeable sender adaptor object.
For a subexpression sndr, let Sndr be decltype((sndr)).
The expression stopped_as_optional(sndr) is expression-equivalent to:transform_sender(get-domain-early(sndr), make-sender(stopped_as_optional, {}, sndr)) except that sndr is only evaluated once.
Let sndr and env be subexpressions such that Sndr is decltype((sndr)) andEnv is decltype((env)).
If sender-for<Sndr, stopped_as_optional_t>is false, or if the type single-sender-value-type<Sndr, Env>is ill-formed or void, then the expression stopped_as_optional.transform_sender(sndr, env)is ill-formed; otherwise, it is equivalent to:auto&& [_, _, child] = sndr;using V = single-sender-value-type<Sndr, Env>;return let_stopped( then(std::forward_like<Sndr>(child),[]<class... Ts>(Ts&&... ts) noexcept(is_nothrow_constructible_v<V, Ts...>) { return optional<V>(in_place, std::forward<Ts>(ts)...);}),[]() noexcept { return just(optional<V>()); });