[task.class]

# 33 Execution control library [[exec]](./#exec)

## 33.13 Coroutine utilities [[exec.coro.util]](exec.coro.util#task.class)

### 33.13.6 execution​::​task [[exec.task]](exec.task#task.class)

#### 33.13.6.2 Class template task [task.class]

namespace std::execution {template<class T, class Environment>class [task](#lib:task "33.13.6.2 Class template task [task.class]") {// [[task.state]](task.state "33.13.6.4 Class template task​::​state")template<[receiver](exec.recv.concepts#concept:receiver "33.7.1 Receiver concepts [exec.recv.concepts]") 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]](task.promise "33.13.6.5 Class task​::​promise_­type")class promise_type;

 task(task&&) noexcept; ~task(); template<[receiver](exec.recv.concepts#concept:receiver "33.7.1 Receiver concepts [exec.recv.concepts]") Rcvr>*state*<Rcvr> connect(Rcvr&& rcvr); private: coroutine_handle<promise_type> *handle*; // *exposition only*};}

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7216)

task<T, E> models [sender](exec.snd.concepts#concept:sender "33.9.3 Sender concepts [exec.snd.concepts]") ([[exec.snd]](exec.snd "33.9 Senders"))
if T is void, a reference type, or a cv-unqualified
non-array object type and E is a class type[.](#1.sentence-1)

Otherwise a program that instantiates the definition of task<T, E> is ill-formed[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7223)

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

- [(2.1)](#2.1)

  allocator_type is Environment​::​allocator_type if that [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") is valid and denotes a type,allocator<byte> otherwise[.](#2.1.sentence-1)

- [(2.2)](#2.2)

  scheduler_type is Environment​::​scheduler_type if that [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") is valid and denotes a type,task_scheduler otherwise[.](#2.2.sentence-1)

- [(2.3)](#2.3)

  stop_source_type is Environment​::​stop_source_type if that [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") is valid and denotes a type,inplace_stop_source otherwise[.](#2.3.sentence-1)

- [(2.4)](#2.4)

  error_types is Environment​::​error_types if
that [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") is valid and denotes a type,completion_signatures<set_error_t(exception_ptr)> otherwise[.](#2.4.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7241)

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[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7247)

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

- [(4.1)](#4.1)

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

- [(4.2)](#4.2)

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

- [(4.3)](#4.3)

set_stopped_t()[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7260)

allocator_type shall meet the *Cpp17Allocator* requirements[.](#5.sentence-1)
