[exec.then] # 33 Execution control library [[exec]](./#exec) ## 33.9 Senders [[exec.snd]](exec.snd#exec.then) ### 33.9.12 Sender adaptors [[exec.adapt]](exec.adapt#exec.then) #### 33.9.12.9 execution​::​then, execution​::​upon_error, execution​::​upon_stopped [exec.then] [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L3757) then attaches an invocable as a continuation for an input sender's value completion operation[.](#1.sentence-1) upon_error and upon_stopped do the same for the error and stopped completion operations, respectively, sending the result of the invocable as a value completion[.](#1.sentence-2) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L3764) The names then, upon_error, and upon_stopped denote pipeable sender adaptor objects[.](#2.sentence-1) Let the expression *then-cpo* be one ofthen, upon_error, or upon_stopped[.](#2.sentence-2) For subexpressions sndr and f, if decltype((sndr)) does not satisfy [sender](exec.snd.concepts#concept:sender "33.9.3 Sender concepts [exec.snd.concepts]"), ordecltype((f)) does not satisfy [*movable-value*](exec.general#concept:movable-value "33.1 General [exec.general]"),*then-cpo*(sndr, f) is ill-formed[.](#2.sentence-3) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L3774) Otherwise, the expression *then-cpo*(sndr, f) is expression-equivalent to:transform_sender(*get-domain-early*(sndr), *make-sender*(*then-cpo*, f, sndr)) except that sndr is evaluated only once[.](#3.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L3782) For then, upon_error, and upon_stopped, let *set-cpo* beset_value, set_error, and set_stopped, respectively[.](#4.sentence-1) The exposition-only class template *impls-for* ([[exec.snd.expos]](exec.snd.expos "33.9.2 Exposition-only entities")) is specialized for *then-cpo* as follows: [🔗](#lib:impls-for%3cdecayed-typeof%3cthen-cpo%3e%3e) namespace std::execution {template<>struct *impls-for*<*decayed-typeof*<*then-cpo*>> : *default-impls* {static constexpr auto *complete* =[](auto, auto& fn, auto& rcvr, Tag, Args&&... args) noexcept -> void {if constexpr ([same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")>) {*TRY-SET-VALUE*(rcvr, invoke(std::move(fn), std::forward(args)...)); } else { Tag()(std::move(rcvr), std::forward(args)...); }}; templatestatic consteval void *check-types*(); };} [🔗](#lib:check-types,impls-for%3cdecayed-typeof%3cthen-cpo%3e%3e) `template static consteval void check-types(); ` [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L3817) *Effects*: Equivalent to:auto cs = get_completion_signatures<*child-type*, *FWD-ENV-T*(Env)...>();auto fn = [](set_value_t(*)(Ts...)) {if constexpr (![invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")>, Ts...>)throw *unspecified-exception*();}; cs.*for-each*(*overload-set*{fn, [](auto){}}); where *unspecified-exception* is a type derived from exception[.](#5.sentence-1) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L3832) The expression *then-cpo*(sndr, f) has undefined behavior unless it returns a sender out_sndr that - [(6.1)](#6.1) invokes f or a copy of such with the value, error, or stopped result datums of sndr for then, upon_error, and upon_stopped, respectively, using the result value of f as out_sndr's value completion, and - [(6.2)](#6.2) forwards all other completion operations unchanged[.](#6.sentence-1)