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 only public: 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<Rcvr> connect(Rcvr&& rcvr); private: coroutine_handle<promise_type> handle; // exposition only }; }
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.
The nested types of task template specializations are determined based on the Environment parameter:
  • allocator_type is Environment​::​allocator_type if that qualified-id is valid and denotes a type, allocator<byte> otherwise.
  • scheduler_type is Environment​::​scheduler_type if that qualified-id is valid and denotes a type, task_scheduler otherwise.
  • stop_source_type is Environment​::​stop_source_type if that qualified-id is valid and denotes a type, inplace_stop_source otherwise.
  • error_types is Environment​::​error_types if that qualified-id is valid and denotes a type, completion_signatures<set_error_t(exception_ptr)> otherwise.
A program is ill-formed if error_types is not a specialization of completion_signatures<ErrorSigs...> or ErrorSigs contains an element which is not of the form set_error_t(E) for some type E.
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 of execution​::​completion_signatures denoted by error_types; and
  • set_stopped_t().
allocator_type shall meet the Cpp17Allocator requirements.