Files
cppdraft_translate/cppdraft/exec/stopped/opt.md
2025-10-25 03:02:53 +03:00

3.1 KiB
Raw Blame History

[exec.stopped.opt]

33 Execution control library [exec]

33.9 Senders [exec.snd]

33.9.12 Sender adaptors [exec.adapt]

33.9.12.14 execution::stopped_as_optional [exec.stopped.opt]

1

#

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.

2

#

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.

3

#

The exposition-only class template impls-for ([exec.snd.expos]) is specialized for stopped_as_optional_t as follows:

🔗

namespace std::execution {template<>struct impls-for<stopped_as_optional_t> : default-impls {template<class Sndr, class... Env>static consteval void check-types() {default-impls::check-types<Sndr, Env...>(); if constexpr (!requires {requires (same_as<void, single-sender-value-type<child-type, FWD-ENV-T(Env)...>>); })throw unspecified-exception(); }};} where unspecified-exception is a type derived from exception.

4

#

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 then the expression stopped_as_optional.transform_sender(sndr, env) is ill-formed; otherwise, if sender_in<child-type, FWD-ENV-T(Env)> is false, the expression stopped_as_optional.transform_sender(sndr, env) is equivalent to not-a-sender(); otherwise, it is equivalent to:auto&& [_, _, child] = sndr;using V = single-sender-value-type<child-type, FWD-ENV-T(Env)>;return let_stopped( then(std::forward_like(child), []<class... Ts>(Ts&&... ts) noexcept(is_nothrow_constructible_v<V, Ts...>) {return optional(in_place, std::forward(ts)...); }), noexcept { return just(optional()); });