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

4.0 KiB
Raw Blame History

[task.class]

33 Execution control library [exec]

33.13 Coroutine utilities [exec.coro.util]

33.13.6 execution::task [exec.task]

33.13.6.2 Class template task [task.class]

namespace std::execution {template<class T, class Environment>class task {// [task.state]template<receiver Rcvr>class state; // exposition onlypublic:using sender_concept = sender_t; using completion_signatures = see below; using allocator_type = see below; using scheduler_type = see below; using stop_source_type = see below; using stop_token_type = decltype(declval<stop_source_type>().get_token()); using error_types = see below; // [task.promise]class promise_type;

task(task&&) noexcept; ~task(); template<receiver Rcvr>state connect(Rcvr&& rcvr); private: coroutine_handle<promise_type> handle; // exposition only};}

1

#

task<T, E> models sender ([exec.snd]) if T is void, a reference type, or a cv-unqualified non-array object type and E is a class type.

Otherwise a program that instantiates the definition of task<T, E> is ill-formed.

2

#

The nested types of task template specializations are determined based on the Environment parameter:

  • (2.1)

    allocator_type is Environment::allocator_type if that qualified-id is valid and denotes a type,allocator otherwise.

  • (2.2)

    scheduler_type is Environment::scheduler_type if that qualified-id is valid and denotes a type,task_scheduler otherwise.

  • (2.3)

    stop_source_type is Environment::stop_source_type if that qualified-id is valid and denotes a type,inplace_stop_source otherwise.

  • (2.4)

    error_types is Environment::error_types if that qualified-id is valid and denotes a type,completion_signatures<set_error_t(exception_ptr)> otherwise.

3

#

A program is ill-formed if error_types is not a specialization of completion_signatures<ErrorSigs...> orErrorSigs contains an element which is not of the formset_error_t(E) for some type E.

4

#

The type alias completion_signatures is a specialization of execution::completion_signatures with the template arguments (in unspecified order):

set_value_t() if T is void, and set_value_t(T) otherwise;

template arguments of the specialization ofexecution::completion_signatures denoted by error_types; and

set_stopped_t().

5

#

allocator_type shall meet the Cpp17Allocator requirements.