Files
cppdraft_translate/cppdraft/task/state.md
2025-10-25 03:02:53 +03:00

4.0 KiB
Raw Blame History

[task.state]

33 Execution control library [exec]

33.13 Coroutine utilities [exec.coro.util]

33.13.6 execution::task [exec.task]

33.13.6.4 Class template task::state [task.state]

namespace std::execution {template<class T, class Environment>template<receiver Rcvr>class task<T, Environment>::state { // exposition onlypublic:using operation_state_concept = operation_state_t; templatestate(coroutine_handle<promise_type> h, R&& rr); ~state(); void start() & noexcept; private:using own-env-t = see below; // exposition only coroutine_handle<promise_type> handle; // exposition only remove_cvref_t rcvr; // exposition only**own-env-t own-env; // exposition only Environment environment; // exposition only};}

1

#

The type own-env-t is Environment::template env_type<decltype(get_env(declval()))> if thatqualified-id is valid and denotes a type, env<> otherwise.

🔗

template<class R> state(coroutine_handle<promise_type> h, R&& rr);

2

#

Effects: Initializes

  • (2.1)

    handle with std::move(h);

  • (2.2)

    rcvr with std::forward(rr);

  • (2.3)

    own-env with own-env-t(get_env(rcvr)) if that expression is valid and own-env-t() otherwise. If neither of these expressions is valid, the program is ill-formed.

  • (2.4)

    environment withEnvironment(own-env) if that expression is valid, otherwise Environment(get_env(rcvr)) if this expression is valid, otherwise Environment(). If neither of these expressions is valid, the program is ill-formed.

🔗

~state();

3

#

Effects: Equivalent to:if (handle)handle.destroy();

🔗

void start() & noexcept;

4

#

Effects: Let prom be the object handle.promise().

Associates STATE(prom), RCVR(prom), and SCHED(prom) with *this as follows:

  • (4.1)

    STATE(prom) is *this.

  • (4.2)

    RCVR(prom) is rcvr.

  • (4.3)

    SCHED(prom) is the object initialized with scheduler_type(get_scheduler(get_env(rcvr))) if that expression is valid and scheduler_type() otherwise. If neither of these expressions is valid, the program is ill-formed.

Let st be get_stop_token(get_env(rcvr)).

Initializes prom.token andprom.source such that

prom.token.stop_requested() returnsst.stop_requested();

prom.token.stop_possible() returnsst.stop_possible(); and

for types Fn and Init such that bothinvocable andconstructible_from<Fn, Init> are modeled,stop_token_type::callback_type modelsstoppable-callback-for<Fn, stop_token_type, Init>.

After that invokes handle.resume().