Document #: | P2999R1 |
Date: | 2023-11-09 |
Project: | Programming Language C++ |
Audience: |
LEWG Library Evolution |
Reply-to: |
Eric Niebler <eric.niebler@gmail.com> |
This paper proposes some design changes to P2300 to address some shortcomings in how algorithm customizations are found.
Many senders do not know on what execution context they will complete, so using solely that information to find customizations (as P2300R7 does) is unsatisfactory.
In [P2300R7], the sender
algorithms (then
,
let_value
, etc) are
customization point objects that internally dispatch via
tag_invoke
to the correct
algorithm implementation. Each algorithm has a default implementation
that is used if no custom implementation is found.
Custom implementations of sender algorithms are found by asking the predecessor sender for its completion scheduler and using the scheduler as a tag for the purpose of tag dispatching. A completion scheduler is a scheduler that refers to the execution context on which that sender will complete.
A typical sender algorithm like
then
might be implemented as
follows:
/// @brief A helper concept for testing whether an algorithm customization
/// exists
template <class AlgoTag, class SetTag, class Sender, class... Args>
concept has-customization =
requires (Sender sndr, Args... args) {
(AlgoTag(),
tag_invoke<SetTag>(get_env(sndr)),
get_completion_scheduler::forward<Sender>(sndr),
std::forward<Args>(args)...);
std};
/// @brief The tag type and the customization point object type for the
/// `then` sender algorithm
struct then_t {
template <sender Sender, class Fun>
requires /* requirements here */
auto operator()(Sender&& sndr, Fun fun) const
{
// If the predecessor sender has a completion scheduler, and if we can use
// the completion scheduler to find a custom implementation for the `then`
// algorithm, dispatch to that. Otherwise, dispatch to the default `then`
// implementation.
if constexpr (has-customization<then_t, set_value_t, Sender, Fun>)
{
auto&& env = get_env(sndr);
return tag_invoke(*this,
<set_value_t>(env),
get_completion_scheduler::forward<Sender>(sndr),
std::move(fun));
std}
else
{
return then-sender<Sender, Fun>(std::forward<Sender>(sndr), std::move(fun));
}
}
};
inline constexpr then_t then {};
This scheme has a number of shortcomings:
A simple sender like
just(42)
does not know its
completion scheduler. It completes on the execution context on which it
is started. That is not known at the time the sender is constructed,
which is when we are looking for customizations.
For a sender like
on( sched, then(just(), fun) )
,
the nested then
sender is
constructed before we have specified the scheduler, but we need the
scheduler to dispatch to the correct customization of
then
. How?
A composite sender like
when_all(sndr1, sndr2)
cannot
know its completion scheduler in the general case. Even if
sndr1
and
sndr2
both know their completion
schedulers – say, sched1
and
sched2
respectively – the
when_all
sender can complete on
either sched1
or sched2
depending on
which of sndr1
and
sndr2
completes last. That is a
dynamic property of the program’s execution, not suitable for finding an
algorithm customization.
In cases (1) and (2), the issue is that the information necessary to find the correct algorithm implementation is not available at the time we look for customizations. In case (3), the issue is that the algorithm semantics make it impossible to know statically to what algorithm customization scheme to dispatch.
The issue described in (2) above is particularly pernicious. Consider
these two programs (where ex::
is a namespace alias for
std::execution
); the differences
are highlighted:
Good
|
Bad
|
---|---|
|
|
These two programs should be equivalent, but they are not.
The author of the
thread_pool_scheduler
gave it a
custom bulk
implementation by
defining:
namespace my {
// customization of the bulk algorithm for the thread_pool_scheduler:
template <ex::sender Sender, std::integral Shape, class Function>
auto tag_invoke(ex::bulk_t,
thread_pool_scheduler sched,&& sndr,
Sender
Shape shape,) {
Function fun/*
* Do bulk work in parallel
* ...
*/
}
}
This overload is found only when the
bulk
sender’s predecessor
completes on a
thread_pool_scheduler
, which is
the case for the code on the left.
In the code to the right, however, the predecessor of the
bulk
operation is
just(data)
, a sender that does
not know where it will complete. As a result, the above customization of
the bulk
algorithm will not be
found, and the bulk operation will execute serially on a single thread
in the thread pool. That’s almost certainly not what the
programmer intended.
This is clearly broken and badly in need of fixing.
Note: On the need for async algorithms customization
It is worth asking why async algorithms need customization at all. After all, the classic STL algorithms need no customization; they dispatch using a fixed concept hierarchy to a closed set of possible implementations.
The reason is because of the open and continually evolving nature of execution contexts. There is little hope of capturing every salient attribute of every interesting execution model – CPUs, GPUs, FPGAs, etc., past, present, and future – in a fixed ontology around which we can build named concepts and immutable basis operations. Instead we do the best we can and then hedge against the future by making the algorithms customizable. For example, say we add an algorithm
std::par_algo
, but we allow that there may be an accelerator “out there” that may dopar_algo
more efficiently than the standard one, so we makepar_algo
customizable.
This section describes at a high level the salient features of the proposed design for sender algorithm customization, and their rationale. But in a nutshell, the basic idea is as follows:
For every invocation of a sender algorithm, the implementation looks for a customization twice: once immediately while the algorithm is constructing a sender to return, and once later when the resulting sender is
connect
-ed with a receiver.
It is the second look-up that is new. By looking for a customization
at connect
time, the dispatching
logic is informed both by information from the predecessor sender(s) as
well as from the receiver. It is the receiver that has information about
the environment of the currently executing asynchronous operation,
information that is key to picking the right customization in the cases
we looked at above.
As described above, the
when_all
sender doesn’t know its
completion scheduler, so we cannot use the completion scheduler to find
the when_all
customization. Even
if all its child senders advertise completion schedulers with the same
type – say, static_thread_pool
–
when_all
itself can’t advertise
a completion scheduler because it doesn’t know that they are all the
same
static_thread_pool
.
In the case just described, consider that we can know the completion scheduler’s type but not its value. So at the very least, we need to add a query about the type of the scheduler apart from its value, for times when we know one but not the other.
Once we have done that, further generalizing the query from a scheduler type to an abstract tag type is a short hop. We call this abstract tag type an execution domain. Several different scheduler types may all want to use the same set of algorithm implementations; those schedulers can all use the same execution domain type for the purpose of dispatching.
If when_all
’s child senders
all share an execution domain, we know the execution domain of the
when_all
sender itself even if
we don’t know which scheduler it will complete on. But that no longer
prevents us from dispatching to the correct implementation.
This paper proposes the addition of a forwarding
get_domain
query in the
std::execution
namespace, and
that the domain is used together with the algorithm tag to dispatch to
the correct algorithm implementation.
Additionally, we proposed that the
when_all
algorithm only accepts
a set of senders when they all share a common domain. Likewise for
let_value
and
let_error
, we require that there
is only one possible domain on which their senders may complete.
As described above, the sender algorithm customization points don’t
have all the information they need to dispatch to the correct algorithm
implementation in all cases. The solution is to look again for a
customization when all the information is available. That happens when
the sender is connect
-ed to a
receiver.
This paper proposes the addition of a
transform_sender
function that
is called by the connect
customization point to transform a sender prior to connecting it with
the receiver. The correct sender transformation is found using a
property read from the receiver’s environment.
The following comparison table shows how we propose to change the
connect
customization point
(changes highlighted):
Before | After |
---|---|
|
|
The use of transform_sender
in connect
it is analagous to
the use of await_transform
in co_await
. Glossing over some
details, in a coroutine the expression
co_await expr
is
“lowered” to operator co_await(p.await_transform(expr)).await_suspend(handle-to-p)
,
where p
is a reference
to coroutine’s promise. This gives the coroutine task type some say in
how co_await
expressions are
evaluated.
The addition of
transform_sender
to P2300
satisfies the same need to customize the launch behavior of child async
tasks. An expression like connect(sndr, detached-receiver)
is “lowered” to connect(transform_sender(domain, sndr, get_env(detached-receiver)), detached-receiver)
,
where domain
is a
property of the receiver’s environment. This gives the receiver some say
in how connect
expressions are
evaluated.
The author anticipates the need to sometimes apply a transformation recursively to all of a sender’s child senders. Such a generic recursive transformation might look something like this:
```c++
// my_domain applies a transformation recursively
auto my_domain::transform_sender(Sender&& sndr, const Env& env) const {
auto [tag, data, child...] = sndr;
// Create a temporary sender with transformed children
auto tmp = make-sender(
tag,
data,
ex::transform_sender(*this, child, env)...);
// Use the transformed children to compute a domain
// (they all must share a domain or it's an error)
auto&& [x, y, child2...] = tmp;
auto domain2 = common-domain-of(child2...);
// Use the predecessor domain to transform the temporary sender:
return ex::transform_sender(domain2, move(tmp), env);
} ```
This works well until we apply this function to a sender that
modifies the environment it passes to its child operations. Take the
case of on(sched, sndr)
: when it
is connected to a receiver, it connects its child sender
sndr
with a receiver whose
environment has been modified to show that the current scheduler is
sched
(because
on
will start
sndr
there).
But the implementation of
my_domain::tranform_sender
above
does not update the environment when it is recursively transforming an
on
sender’s child. That means
the child will be transformed with incorrect information about where it
will be executing, which can change the meaning of the transformation.
That’s not good. Something is missing.
We need a way to ask a sender to apply its transformation to an
environment. That is, in addition to
transform_sender
we need
transform_env
that can be used
to fix the code above as follows (differences highlighted):
```c++
// my_domain applies a transformation recursively
auto my_domain::transform_sender(Sender&& sndr, const Env& env) const {
auto [tag, data, child...] = sndr;
// Apply any necessary transformations to the environmentauto&& env2 = ex::transform_env(*this, sndr, env);
// Create a temporary sender with transformed children,
// using the transformed environment from the line above
auto tmp = make-sender(
tag,
data,env2
)...);
ex::transform_sender(*this, child,
// Use the transformed children to compute a domain
// (they all must share a domain or it's an error)
auto&& [x, y, child2...] = tmp;
auto domain2 = common-domain-of(child2...);
// Use the predecessor domain to transform the temporary sender:
return ex::transform_sender(domain2, move(tmp), env);
} ```
Now expressions can generically be transformed recursively.
We can use transform_sender
for early customization as well as late. The benefit of doing this is
that only one set of customizations needs be written for each domain,
rather than two (early and late).
This paper proposes that each algorithm constructs a default sender
that implements the default behavior for that algorithm. It then passes
that sender to transform_sender
along with the sender’s domain. The result of
transform_sender
is what the
algorithm returns.
The following comparison table shows how we propose to change the
connect
customization point
(changes highlighted):
Before | After |
---|---|
|
|
Some algorithms are required to do some work eagerly in their default
implementation (e.g.,
split
,
ensure_started
). These
algorithms must first create a dummy sender to pass to
transform_sender
. The “default”
domain, which is used when no other domain has been specified, can
transform these dummy senders and do their eager work in the process.
The same mechanism is also useful to implement customizable sender
algorithms whose default implementation merely lowers to a more
primitive expression (e.g.
transfer(s,sch)
becomes
schedule_from(sch,s)
, and
transfer_just(sch, ts...)
becomes
just(ts...) | transfer(sch)
).
For example, here is how the
transfer_just
customization
point might look after the change:
Before | After |
---|---|
|
|
Some algorithms are entirely eager with no lazy component, like
sync_wait
and
start_detached
. For these,
“transforming” a sender isn’t what you want; you want to dispatch to an
eager algorithm that will actually consume the sender. We can
use domains to dispatch to the correct implementation for those as well.
This paper proposes the addition of an
apply_sender
function.
The following table describes the differences between
transform_sender
and
apply_sender
:
transform_sender
|
apply_sender
|
---|---|
|
|
To permit third parties to author customizable sender algorithms with
partly or fully eager behavior, the mechanism by which the default
domain finds the default
transform_sender
and
apply_sender
implementations
shall be specified: they both dispatch to similarly named functions on
the tag type of the input sender; i.e., default_domain().transform_sender(sndr, env)
is equal to tag_of_t<decltype(sndr)>().transform_sender(sndr, env)
.
For the transform_sender
customization point to be useful, we need a way to access the
constituent pieces of a sender and re-assemble it from (possibly
transformed) pieces. Senders, like coroutines, generally begin in a
“suspended” state; they merely curry their algorithm’s arguments into a
subsequent call to connect
.
These “suspended” senders are colloquially known as lazy
senders.
Each lazy sender has an associated algorithm tag, a (possibly empty)
set of auxiliary data and a (possibly empty) set of child senders;
e.g., the sender returned from
then(snd, fun)
has
then_t
as its tag, the set
[fun]
as its auxiliary data, and
[snd]
as its set of child
senders, while just(42, 3.14)
has just_t
as its tag,
[42, 3.14]
as its data set and
[]
as its child set.
This paper proposes to use structured bindings as the API for decomposing a lazy sender into its tag, data, and child senders:
auto&& [tag, data, ...children] = sndr;
[P1061R5], currently in Core wording review for C++26, permits the declaration of variadic structured bindings like above, making this syntax very appealing.
Not all senders are required to be decomposable, although all the
“standard” lazy senders shall be. There needs to be a syntactic way to
distinguish between decomposable and ordinary,non-decomposable senders
(decomposable senders subsuming the
sender
concept).
There is currently no trait for determining whether a type can be the initializer of a structured binding. However, EWG has already approved [P2141R1] for C++26, and with it such a trait could be built, giving us a simple way to distinguish between decomposable and non-decomposable senders.
If P2141 is not adopted for C++26, we will need some other syntactic
way to opt-in. One possibility is to require that the sender type’s
nested is_sender
type shall have
some known, standard tag type as a base class to signify that that
sender type can be decomposed.
After decomposing a sender, it is often desirable to re-compose it
from its modified constituents. No separate API for reconstituting
senders is necessary though. It is enough to construct a decomposable
sender of some arbitrary type and then pass it to
transform_sender
with an
execution domain to place it in its final form.
Consider the case where
my_domain::transform_sender()
is
passed
your_sender<Children...>
.
It unpacks it into its tag/data/children constituents and munges the
children somehow. It then wants to reconstruct a
your_sender
from the munged
children. Instead, it constructs arbitrary-sender{tag, data, munged_children}
and passes it to
execution::transform_sender()
along with your_domain
, the
domain associated with
your_sender
. That presumably
will transform the
arbitrary-sender
back
into a your_sender
.
In condensed form, here are the changes this paper is proposing:
Add a default_domain
type
for use when no other domain is determinable.
Add a new get_domain(env) -> domain-tag
forwarding query.
Add a new transform_sender(domain, sender [, env]) -> sender
API. This function is not itself customizable, but it will be used for
both early customization (at sender construction-time) and late
customization (at sender/receiver connection-time).
Early customization:
domain
is derived
from the sender by trying the following in order:
get_domain(get_env(sender))
get_domain(get_completion_scheduler<completion-tag>(get_env(sender)))
,
where completion-tag
is
one of set_value_t
,
set_error_t
, or
set_stopped_t
depending on the
algorithmdefault_domain()
Late customization:
connect
customization point object before tag-dispatching with
connect_t
to
tag_invoke
domain
is derived
from the receiver by trying the following in order:
get_domain(get_env(receiver))
get_domain(get_scheduler(get_env(receiver)))
default_domain()
transform_sender(domain, sender [, env])
returns the first of these that is well-formed:
domain.transform_sender(sender [, env])
default_domain().transform_sender(sender [, env])
sender
Add a transform_env(domain, sender, env) -> env’
API in support of generic recursive sender transformations. The
domain
argument is
determined from env
as
for transform_sender
transform_env(domain, sender, env)
returns the first of these that is well-formed:
domain.transform_env(sender, env)
default_domain().transform_env(sender, env)
The standard, “lazy” sender types (i.e., those returned from sender factory and adaptor functions) return sender types that are decomposable using structured bindings into its [tag, data, …children] components.
A call to the when_all
algorithm should be ill-formed unless all of the sender arguments have
the same domain type (as determined for senders above). The resulting
when_all
sender should publish
that domain via the sender’s environment.
The on(sch, sndr)
algorithm should be specified in terms of
transfer
so as to pick up any
late customization of the
transfer
algorithm. (This
amounts to changing
schedule(sch)
to
transfer_just(sch)
in
[exec.on]/3.2.2.). Additionally, it should replace the domain in the
receiver’s environment with the domain of
sch
.
The sender factories
just
,
just_error
, and
just_stopped
need their tag
types to be specified. Name them
just_t
,
just_error_t
, and
just_stopped_t
.
In the algorithm
let_value(sndr, fun)
, if the
predecessor sender sndr
has a
completion scheduler for
set_value
, then the receiver
connected to the secondary sender (the one returned from
fun
when called with
sndr
’s results) shall expose
that scheduler as the current scheduler of the receiver’s
environment.
In other words, if the predecessor sender
sndr
completes with values
vs...
, then the result of
fun(vs...)
will be connected to
a receiver r
such that
get_scheduler(get_env(r))
is
equal to get_completion_scheduler<set_value_t>(get_env(sndr))
.
The same is true also of the domain query:
get_domain(get_env(r))
is equal
to the domain of the predecessor sender as computed by the steps in (2)
above.
So for let_value
, likewise
also for let_error
and
let_stopped
, using
set_error_t
and
set_stopped
respectively when
querying for the predecessor sender’s completion scheduler and
domain.
The
schedule_from(sched, sndr)
algorithm should return a sender
s
such that
get_domain(get_env(s))
is equal
to get_domain(sched)
.
The following customizable algorithms, whose default
implementations must do work before returning the result sender, will
have their work performed in overloads of
default_domain::transform_sender
:
split
ensure_started
The following customizable algorithms, whose default
implementations are trivially expressed in terms of other more primitive
operations, will be lowered into their primitive forms by overloads of
default_domain::transform_sender
:
transfer
transfer_just
transfer_when_all
transfer_when_all_with_variant
when_all_with_variant
In the algorithm
let_value(snd, fun)
, all of the
sender types that the input function
fun
might return – the set of
potential result senders – must all have the same domain; otherwise, the
call to let_value
is
ill-formed.
Ideally, the let_value
sender
would report the result senders’ domain as its domain, however we don’t
know the set of completions until the
let_value
sender is connected to
a receiver; hence, we also don’t know the set of potential result
senders or their domains. Instead, we require that all the result
senders share an execution domain with the predecessor sender. If they
differ, connect
is
ill-formed.
For example, consider the following sender:
auto snd = (get_scheduler) read| transfer(schA) | let_value([](auto schB){ return schedule(schB); })
This reads the current scheduler from the receiver, transfers
execution to schA
, and then
(indirectly, through let_value
)
transitions onto the scheduler read from the receiver
(schB
). This sender can be
connect
-ed only to receivers
R
for which the scheduler
get_scheduler(get_env(R))
has
the same execution domain as that of
schA
.
Likewise for let_error
and
let_stopped
.
This solution is not ideal. I am currently working on a more flexible solution, but I’m not yet sufficiently confident in it to propose it here.
Add a new apply_sender(domain, tag, sender, args...) -> result
API. Like transform_sender
, this
function is not itself customizable, but it will be used to customize
sender consuming algorithms such as
start_detached
and
sync_wait
.
domain
is
determined as for
transform_sender
apply_sender(domain, tag, sender, args...)
returns the first of these that is well-formed:
domain.apply_sender(tag, sender, args...)
default_domain().apply_sender(tag, sender, args...)
The following customizable sender-consuming algorithms will have
their default implementations in overloads of
default_domain::apply_sender
:
start_detached
sync_wait
Has it been implented? YES. The design changes herein
proposed are implemented in the main branch of [stdexecgithub], the reference
implementation. The bulk of the changes including
get_domain
,
transform_sender
, and the
changes to connect
have been
shipping since this
commit on August 3, 2023 which changed the
static_thread_pool
scheduler to
use transform_sender
to
parallelize the bulk
algorithm.
The following proposed changes are relative to [P2300R7].
[ Editor's note: Change §11.4 [exec.syn] as follows: ]
// [exec.queries], queries
enum class forward_progress_guarantee;
namespace queries { // exposition onlystruct get_domain_t;
struct get_scheduler_t;
struct get_delegatee_scheduler_t;
struct get_forward_progress_guarantee_t;
template<class CPO>
struct get_completion_scheduler_t;
}
using queries::get_domain_t;
using queries::get_scheduler_t;
using queries::get_delegatee_scheduler_t;
using queries::get_forward_progress_guarantee_t;
using queries::get_completion_scheduler_t;inline constexpr get_domain_t get_domain{};
inline constexpr get_scheduler_t get_scheduler{};
inline constexpr get_delegatee_scheduler_t get_delegatee_scheduler{};
inline constexpr get_forward_progress_guarantee_t get_forward_progress_guarantee{};
template<class CPO>
inline constexpr get_completion_scheduler_t<CPO> get_completion_scheduler{};
// [exec.domain.default], domains
struct default_domain;
[ Editor's note: … and … ]
template<class S, class E = empty_env>
requires sender_in<S, E>
inline constexpr bool sends_stopped = see below;
template <sender Sender>
using tag_of_t = see below;
// [exec.snd.transform], sender transformations
template <class Domain, sender Sender, class... Env>
requires (sizeof...(Env) <= 1)
constexpr sender decltype(auto) transform_sender(Domain dom, Sender&& sndr, const Env&... env) noexcept(see below);
template <class Domain, sender Sender, class Env>
constexpr decltype(auto) transform_env(Domain dom, Sender&& sndr, Env&& env) noexcept;
// [exec.snd.apply], sender algorithm application
template <class Domain, class Tag, sender Sender, class... Args>
constexpr decltype(auto) apply_sender(Domain dom, Tag, Sender&& sndr, Args&&... args) noexcept(see below);
// [exec.connect], the connect sender algorithm
namespace senders-connect { // exposition only
struct connect_t;
}
using senders-connect::connect_t; inline constexpr connect_t connect{};
[ Editor's note: … and … ]
// [exec.factories], sender factories
namespace senders-factories { // exposition onlystruct just_t;
struct just_error_t;
struct just_stopped_t;
struct schedule_t;
struct transfer_just_t;
}using sender-factories::just_t;
using sender-factories::just_error_t;
using sender-factories::just_stopped_t;
unspecifiedjust_t just{};
inline constexpr unspecifiedjust_error_t just_error{};
inline constexpr unspecifiedjust_stopped_t just_stopped{}; inline constexpr
[ Editor's note: After §11.5.4 [exec.get.stop.token], add the following new subsection: ]
§11.5.?
execution::get_domain
[exec.get.domain]
get_domain
asks an object
for an associated execution domain tag.
The name get_domain
denotes a query object. For some subexpression
r
,
get_domain(r)
is
expression-equivalent to mandate-nothrow-call(tag_invoke, get_domain, as_const(r))
,
if this expression is well-formed.
std::forwarding_query(execution::get_domain)
is true
.
get_domain()
(with no
arguments) is expression-equivalent to
execution::read(get_domain)
([exec.read]).
[ Editor's note: To section §11.6 [exec.sched], insert a new paragraph between 6 and 7 as follows: ]
s
, if the expression
get_domain(s)
is well-formed,
then the expression
get_domain(get_env(schedule(s)))
is also well-formed and has the same type.[ Editor's note: To section §11.9.1 [exec.snd.concepts], after paragraph 4, add two new paragraphs as follows: ]
Let s
be an expression
such that decltype((s))
is
S
. The type
tag_of_t<S>
is as
follows:
If the declaration auto&& [tag, data, ...children] = s;
would be well-formed,
tag_of_t<S>
is an alias
for
decltype(auto(tag))
.
Otherwise,
tag_of_t<S>
is
ill-formed.
[ Editor's note: There is no way in standard C++ to determine whether the above declaration is well-formed without causing a hard error, so this presumes compiler magic. However, the author anticipates the adoption of [P2141R1], which makes it possible to implement this purely in the library. P2141 has already been approved by EWG for C++26. ]
Let sender-for
be an exposition-only concept defined as follows:
template <class Sender, class Tag> concept sender-for = sender<Sender> && same_as<tag_of_t<Sender>, Tag>;
[ Editor's note: After §11.9.2 [exec.awaitables], add the following new subsections: ]
§11.9.?
execution::default_domain
[exec.domain.default]
struct default_domain {
template <sender Sender, class... Env>
requires (sizeof...(Env) <= 1)
static constexpr sender decltype(auto) transform_sender(Sender&& sndr, const Env&... env) noexcept(see below);
template <sender Sender, class Env>
static constexpr decltype(auto) transform_env(Sender&& sndr, Env&& env) noexcept;
template <class Tag, sender Sender, class... Args>
static constexpr decltype(auto) apply_sender(Tag, Sender&& sndr, Args&&... args) noexcept(see below); };
§11.9.?.1 Static members [exec.domain.default.statics]
template <sender Sender, class... Env>
requires (sizeof...(Env) <= 1) constexpr sender decltype(auto) default_domain::transform_sender(Sender&& sndr, const Env&... env) noexcept(see below);
Returns: tag_of_t<Sender>().transform_sender(std::forward<Sender>(sndr), env...)
if that expression is well-formed; otherwise,
std::forward<Sender>(sndr)
.
Remarks: The exception specification is equivalent to:
noexcept(tag_of_t<Sender>().transform_sender(std::forward<Sender>(sndr), env...))
if that expression is well-formed; otherwise,
true
;
template <sender Sender, class Env> constexpr decltype(auto) default_domain::transform_env(Sender&& sndr, Env&& env) noexcept;
Returns: tag_of_t<Sender>().transform_env(std::forward<Sender>(sndr), std::forward<Env>(env))
if that expression is well-formed; otherwise, static_cast<Env>(std::forward<Env>(env))
.
Mandates: The selected expression in Returns: is not potentially throwing.
template <class Tag, sender Sender, class... Args> static constexpr decltype(auto) default_domain::apply_sender(Tag, Sender&& sndr, Args&&... args) noexcept(see below);
Returns: Tag().apply_sender(std::forward<Sender>(sndr), std::forward<Args>(args)...)
if that expression is well-formed; otherwise, this function shall not
participate in overload resolution.
Remarks: The exception specification is equivalent to:
noexcept(Tag().apply_sender(std::forward<Sender>(sndr), std::forward<Args>(args)...))
§11.9.?
execution::transform_sender
[exec.snd.transform]
template <class Domain, sender Sender, class... Env>
requires (sizeof...(Env) <= 1) constexpr sender decltype(auto) transform_sender(Domain dom, Sender&& sndr, const Env&... env) noexcept(see below);
Returns: dom.transform_sender(std::forward<Sender>(sndr), env...)
if that expression is well-formed; otherwise, default_domain().transform_sender(std::forward<Sender>(sndr), env...)
.
Remarks: The exception specification is equivalent to:
noexcept(dom.transform_sender(std::forward<Sender>(sndr), env...))
if that expression is well-formed; otherwise,
noexcept(default_domain().transform_sender(std::forward<Sender>(sndr), env...))
template <class Domain, sender Sender, class Env> constexpr decltype(auto) transform_env(Domain dom, Sender&& sndr, Env&& env) noexcept;
Returns: dom.transform_sender(std::forward<Sender>(sndr), std::forward<Env>(env))
if that expression is well-formed; otherwise, default_domain().transform_sender(std::forward<Sender>(sndr), std::forward<Env>(env))
.
§11.9.?
execution::apply_sender
[exec.snd.apply]
template <class Domain, class Tag, sender Sender, class... Args> constexpr decltype(auto) apply_sender(Domain dom, Tag, Sender&& sndr, Args&&... args) noexcept(see below);
Returns: dom.apply_sender(Tag(), std::forward<Sender>(sndr), std::forward<Args>(args)...)
if that expression is well-formed; otherwise, default_domain().apply_sender(Tag(), std::forward<Sender>(sndr), std::forward<Args>(args)...)
if that expression is well-formed; otherwise, this function shall not
participate in overload resolution.
Remarks: The exception specification is equivalent to:
noexcept(dom.apply_sender(Tag(), std::forward<Sender>(sndr), std::forward<Args>(args)...))
if that expression is well-formed; otherwise,
noexcept(default_domain().apply_sender(Tag(), std::forward<Sender>(sndr), std::forward<Args>(args)...))
[ Editor's note: Add a paragraph to §11.9 [exec.snd] ]
This section makes use of the following exposition-only entities.
template <class Tag, class Env, class Default> constexpr decltype(auto) query-with-default(Tag, const Env& env, Default&& value) noexcept(see below);
Effects: Equivalent to:
— return Tag()(env);
if that
expression is well-formed,
— return static_cast<Default>(std::forward<Default>(value));
otherwise.
Remarks: The expression in the
noexcept
clause is:
is_invocable_v<Tag, const Env&> ? is_nothrow_invocable_v<Tag, const Env&> : is_nothrow_constructible_v<Default, Default>
template <class Env, class Tag = get_scheduler_t> constexpr auto get-env-domain(const Env& env, Tag tag = {}) noexcept;
Effects: Equivalent to:
— return get_domain(env);
if
that expression is well-formed,
— otherwise,
return get_domain(tag(env));
if
that expression is well-formed,
— otherwise,
return default_domain();
.
template <class Sender, class Tag = set_value_t> constexpr auto get-sender-domain(const Sender& sndr, Tag = {}) noexcept;
Effects: Equivalent to: return get-env-domain(get_env(sndr), get_completion_scheduler<Tag>);
.
template <class... T>
struct tuple-like {
T0 t0; // exposition only
T1 t1; // exposition only
...
Tn-1 tn-1; // exposition only };
— [ Note: An expression of
type tuple-like
is
usable as the initializer of a structured binding declaration
[dcl.struct.bind]. — end note ]
template <semiregular Tag, movable-value Data, sender... Child> constexpr auto make-sender(Tag, Data&& data, Child&&... child);
Returns: A prvalue of type basic-sender<Tag, decay_t<Data>, decay_t<Child>...>
where the tag
member
has been default-initialized and the
data
and childn...
members have been direct initialized from their respective forwarded
arguments, where
basic-sender
is the
following exposition-only class template except as noted below:
template <class Tag, class Data, class... Child> // arguments are not associated entities ([lib.tmpl-heads]) struct basic-sender : unspecified { using is_sender = unspecified; [[no_unique_address]] Tag tag; // exposition only Data data; // exposition only Child0 child0; // exposition only Child1 child1; // exposition only ... Childn-1 childn-1; // exposition only };
— It is unspecified whether instances of
basic-sender
can be
aggregate initialized.
— The unspecified base type has no non-static data members. It may define member functions or hidden friend functions ([hidden.friends]).
— [ Note: An expression of
type basic-sender
is
usable as the initializer of a structured binding declaration
[dcl.struct.bind]. — end note ]
template <class Domain, class... Env>
auto make-transformer-fn(Domain, const Env&... env) {
return [&]<class Tag>(Tag) {
return [&]<class... Args>(Args&&... args) -> decltype(auto) {
return transform_sender(Domain(), Tag()(std::forward<Args>(args)...), env...);
};
}; }
[ Editor's note: To §11.9.5.2 [exec.just], add a paragraph 6 as follows: ]
just-sender<Tag, Ts...>
behave as do expressions of type basic-sender<Tag, tuple-like<Ts...>>
.[ Editor's note: Change §11.9.5.3 [exec.transfer.just] as follows (some identifiers in this section have had their names changed for the sake of clarity; the name changes have not been marked up): ]
The name transfer_just
denotes a customization point object. For some subexpression
sch
and pack of subexpressions
vs
, let
Sch
be
decltype((sch))
and let
Vs
be the template parameter
pack decltype((vs))...
. If
Sch
does not satisfy
scheduler
, or any type
V
in
Vs
does not satisfy
movable-value
,
transfer_just(sch, vs...)
is
ill-formed. Otherwise,
transfer_just(sch, vs...)
is
expression-equivalent to:
transform_sender( query-or-default(get_domain, sch, default_domain()), make-sender(transfer_just, tuple-like{sch, vs...}));
tag_invoke(transfer_just, sch, vs...)
,
if that expression is valid.Let as
be a pack of
rvalue subexpressions of types
decay_t<Vs>...
refering to
objects direct-initilized from
vs
. If the function selected by
a sender
tag_invoke
S
returned from
transfer_just(sch, vs...)
is connected with a receiver
R
with environment
E
such that
transform_sender(get-env-domain(E), S, E)
does not return a sender whose asynchronous operations execute value
completion operations on an execution agent belonging to the execution
resource associated with sch
,
with value result datums as
, the
behavior of calling transfer_just(sch, vs...)
connect(S, R)
is undefined.
sender_of<RS, set_value_t(decay_t<Vs>...), E>
,
where
RS
is the
type of tag_invoke
expression abovetransfer_just(sch, vs...)
,
and E
is the type of an
environment.
- Otherwise,
transfer(just(vs...), sch)
.
For some subexpression
sch
and pack of subexpressions
vs
, let
s
be a subexpression refering to
an object returned from
transform_just(sch, vs...)
or a
copy of such. Then get_completion_scheduler<set_value_t>(get_env(s)) == sch
is true
, get_completion_scheduler<set_stopped_t>(get_env(s)) == sch
is true
, and
get_domain(get_env(s))
is
expression-equivalent to
get_domain(sch)
.
Let s
and
e
be subexpressions such that
S
is
decltype((s))
. If sender-for<S, transfer_just_t>
is false
, then the expression
transfer_just_t().transform_sender(s, e)
is ill-formed; otherwise, it is equal to:
const auto& env = e; auto domain = get-env-domain(env); auto [tag, data] = s; auto& [sched, ...vs] = data; auto tfx = make-transformer-fn(domain, env); return tfx(transfer)(tfx(just)(std::move(vs)...), std::move(sched));
[ Note: This causes the
transform_just(sch, vs...)
sender to become
transform(just(vs...), sch)
when
it is connected with a receiver whose execution domain does not
customize transform_just
.
— end note ]
[ Editor's note: Update §11.9.6.3 [exec.on] as follows: ]
on
adapts an input sender
into a sender that will start on an execution agent belonging to a
particular scheduler’s associated execution resource.
Let
replace-scheduler(e, sch)
be an expression denoting an object
e'
such that
get_scheduler(e')
returns a copy of sch
, get_domain(e')
is expression-equivalent to
get_domain(sch)
,
and
tag_invoke(tag, e', args...)
is expression-equivalent to
tag(e, args...)
for all
arguments args...
and for all
tag
whose type satisfies
forwarding-query
and is
not get_scheduler_t
or
get_domain_t
.
The name on
denotes a
customization point object. For some subexpressions
sch
and
s
, let
Sch
be
decltype((sch))
and
S
be
decltype((s))
. If
Sch
does not satisfy
scheduler
, or
S
does not satisfy
sender
,
on(sch, s)
is ill-formed. Otherwise, the expression
on(sch, s)
is
expression-equivalent to:
transform_sender( query-or-default(get_domain, sch, default_domain()), make-sender(on, sch, s));
If a
sender tag_invoke(on, sch, s)
,
if that expression is valid. If the function selected
aboveS
returned
from on(sch, s)
is
connected with a receiver
R
with environment
E
such that
transform_sender(get-env-domain(E), S, E)
does not return a sender which starts
s
on an execution agent of the
associated execution resource of
sch
when started, the behavior
of calling on(sch, s)
connect(S, R)
is undefined.
tag_invoke
expression above satisfies
sender
.Let
s
and
e
be subexpressions
such that S
is
decltype((s))
. If
sender-for<S, on_t>
is false
, then the
expression
on_t().transform_sender(s, e)
is ill-formed; otherwise, it returns Otherwise, constructs a sender
s1
. Whensuch that when
s1
is connected with some
receiver out_r
, it:
Constructs a receiver r
such that:
When set_value(r)
is
called, it calls connect(s, r2)
,
where r2
is as specified below,
which results in op_state3
. It
calls start(op_state3)
. If any
of these throws an exception, it calls
set_error
on
out_r
, passing
current_exception()
as the
second argument.
set_error(r, e)
is
expression-equivalent to
set_error(out_r, e)
.
set_stopped(r)
is
expression-equivalent to
set_stopped(out_r)
.
get_env(r)
is
expression-equivalent to
get_env(out_r)
.
Calls schedule(sch)
transfer_just(sch)
,
which results in s2
. It then
calls connect(s2, r)
, resulting
in op_state2
.
op_state2
is wrapped by a
new operation state, op_state1
,
that is returned to the caller.
r2
is a receiver that
wraps a reference to out_r
and
forwards all completion operations to it. In addition,
get_env(r2)
returns
replace-scheduler(e, sch)
.
When start
is called on
op_state1
, it calls
start
on
op_state2
.
The lifetime of
op_state2
, once constructed,
lasts until either op_state3
is
constructed or op_state1
is
destroyed, whichever comes first. The lifetime of
op_state3
, once constructed,
lasts until op_state1
is
destroyed.
Let
s
and
e
be subexpressions
such that S
is
decltype((s))
. If
sender-for<S, on_t>
is false
, then the
expression
on_t().transform_env(s, e)
is ill-formed; otherwise, let
sch
be the
scheduler used to construct
s
.
on_t().transform_env(s, e)
is equal to
replace-scheduler(e, sch)
.
Given subexpressions s1
and e
, where
s1
is a sender returned from
on
or a copy of such, let
S1
be
decltype((s1))
. Let
E'
be decltype((replace-scheduler(e, sch)))
.
Then the type of tag_invoke(get_completion_signatures, s1, e)
shall be:
make_completion_signatures< copy_cvref_t<S1, S>, E', make_completion_signatures< schedule_result_t<Sch>, E, completion_signatures<set_error_t(exception_ptr)>, no-value-completions>>;
where no-value-completions<As...>
names the type
completion_signatures<>
for any set of types
As...
.
[ Editor's note: Update §11.9.6.4 [exec.transfer] as follows: ]
transfer
adapts a sender
into a sender with a different associated
set_value
completion scheduler.
[ Note: It results in a
transition between different execution resources when executed. —
end note ]
The name transfer
denotes
a customization point object. For some subexpressions
sch
and
s
, let
Sch
be
decltype((sch))
and
S
be
decltype((s))
. If
Sch
does not satisfy
scheduler
, or
S
does not satisfy
sender
,
transfer(s, sch)
is ill-formed. Otherwise, the expression
transfer(s, sch)
is
expression-equivalent to:
transform_sender( get-sender-domain(s), make-sender(transfer, sch, s));
tag_invoke(transfer, get_completion_scheduler<set_value_t>(get_env(s)), s, sch)
,
if that expression is valid.
tag_invoke
expression above
satisfies sender
.Otherwise,
tag_invoke(transfer, s, sch)
, if
that expression is valid.
tag_invoke
expression above
satisfies sender
.Otherwise,
schedule_from(sch, s)
.
If the function selected aboveIf a senderS
returned fromtransfer(s, sch)
is connected with a receiverR
with environmentE
such thattransform_sender(get-env-domain(E), S, E)
does not return a senderwhichthat is a result of a call totransform_sender(get-env-domain(E),schedule_from(sch, s2), E)
, wheres2
is a senderwhichthat sends valuesequivalentequal to those sent bys
, the behavior of callingtransfer(s, sch)
connect(S, R)
is undefined.
t
returned from
transfer(s, sch)
,
get_env(t)
shall return a
queryable object q
such that
get_domain(q)
is expression-equivalent to
get_domain(sch)
and get_completion_scheduler<CPO>(q)
returns a copy of sch
, where
CPO
is either
set_value_t
or
set_stopped_t
. The get_completion_scheduler<set_error_t>
query is not implemented, as the scheduler cannot be guaranteed in case
an error is thrown while trying to schedule work on the given scheduler
object. For all other query objects
Q
whose type satisfies
forwarding-query
, the
expression
Q(q, args...)
shall be
equivalent to
Q(get_env(s), args...)
.Let s
and
e
be subexpressions such that
S
is
decltype((s))
. If sender-for<S, transfer_t>
is false
, then the expression
transfer_t().transform_sender(s, e)
is
ill-formed; otherwise, it is equal to:
const auto& env = e; auto domain = get-env-domain(env); auto [tag, data, child] = s; auto tfx = make-transformer-fn(domain, env); return tfx(schedule_from)(std::move(data), std::move(child));
[ Note: This causes the
transfer(s, sch)
sender to
become schedule_from(sch, s)
when it is connected with a receiver whose execution domain does not
customize transfer
. —
end note ]
[ Editor's note: Update §11.9.6.5 [exec.schedule.from] as follows: ]
schedule_from
schedules
work dependent on the completion of a sender onto a scheduler’s
associated execution resource. [ Note:
schedule_from
is not
meant to be used in user code; it is used in the implementation of
transfer
. — end
note ]
The name schedule_from
denotes a customization point object. For some subexpressions
sch
and
s
, let
Sch
be
decltype((sch))
and
S
be
decltype((s))
. If
Sch
does not satisfy
scheduler
, or
S
does not satisfy
sender
,
schedule_from(sch, s)
is ill-formed. Otherwise, the expression
schedule_from(sch, s)
is
expression-equivalent to:
transform_sender( query-or-default(get_domain, sch, default_domain()), make-schedule-from-sender(sch, s));
make-schedule-from-sender(sch, s)
is expression-equivalent to make-sender(schedule_from, sch, s)
and returns a sender object s2
that behaves as follows:
tag_invoke(schedule_from, sch, s)
, if
that expression is valid. If the function selected by
tag_invoke
does not return a
sender that completes on an execution agent belonging to the associated
execution resource of sch
and
completing with the same async result ([async.ops]) as
s
, the behavior of calling
schedule_from(sch, s)
is
undefined.
tag_invoke
expression above
satisfies sender
.
Otherwise,
constructs a sender
When s2
.s2
is connected with some
receiver out_r
, it:
Constructs a receiver r
such that when a receiver completion operation
Tag(r, args...)
is
called, it decay-copies args...
into op_state
(see below) as
and
constructs a receiver args'args2...r2
such
that:
When set_value(r2)
is
called, it calls Tag(out_r, std::move(
.args'args2)...)
set_error(r2, e)
is
expression-equivalent to
set_error(out_r, e)
.
set_stopped(r2)
is
expression-equivalent to
set_stopped(out_r)
.
get_env(r2)
is equal to
get_env(r)
.
It then calls schedule(sch)
,
resulting in a sender s3
. It
then calls connect(s3, r2)
,
resulting in an operation state
op_state3
. It then calls
start(op_state3)
. If any of
these throws an exception, it catches it and calls set_error(out_r, current_exception())
.
If any of these expressions would be ill-formed, then
Tag(r, args...)
is
ill-formed.
Calls connect(s, r)
resulting in an operation state
op_state2
. If this expression
would be ill-formed,
connect(s2, out_r)
is
ill-formed.
Returns an operation state
op_state
that contains
op_state2
. When
start(op_state)
is called, calls
start(op_state2)
. The lifetime
of op_state3
ends when
op_state
is destroyed.
[ Editor's note: This
para is taken from the removed para (1) above. ] If the function selected by
If a sender
tag_invoke
S
returned from
schedule_from(sch, s)
is connected with a receiver
R
with environmment
E
such that
transform_sender(get-env-domain(E), S, E)
does not return a sender that completes on an execution agent belonging
to the associated execution resource of
sch
and completing with the same async
result ([async.ops]) as s
, the
behavior of calling schedule_from(sch, s)
connect(S, R)
is undefined.
Given subexpressions s2
and e
, where
s2
is a sender returned from
schedule_from
or a copy of such,
let S2
be
decltype((s2))
and let
E
be
decltype((e))
. Then the type of
tag_invoke(get_completion_signatures, s2, e)
shall be:
make_completion_signatures< copy_cvref_t<S2, S>, E, make_completion_signatures< schedule_result_t<Sch>, E, potentially-throwing-completions, no-completions>, value-completions, error-completions>;
where
potentially-throwing-completions
,
no-completions
,
value-completions
, and
error-completions
are
defined as follows:
template <class... Ts> using all-nothrow-decay-copyable =
boolean_constant<(is_nothrow_constructible_v<decay_t<Ts>, Ts> && ...)>
conjunction<is_nothrow_constructible<decay_t<Ts>, Ts>...>
;template <class... Ts>
using potentially-throwing-completions = conditional_t< error_types_of_t<copy_cvref_t<S2, S>, E, all-nothrow-decay-copyable>::value &&using conjunction = boolean_constant<(Ts::value &&...)>;
conjunctionconjunction>::value, value_types_of_t<copy_cvref_t<S2, S>, E, all-nothrow-decay-copyable, completion_signatures<>, completion_signatures<set_error_t(exception_ptr)>; template <class...> using no-completions = completion_signatures<>; template <class... Ts> using value-completions = completion_signatures<set_value_t(decay_t<Ts>&&...)>; template <class T> using error-completions = completion_signatures<set_error_t(decay_t<T>&&)>;
t
returned from
schedule_from(sch, s)
,
get_env(t)
shall return a
queryable object q
such that
get_domain(q)
is expression-equivalent to
get_domain(sch)
and get_completion_scheduler<CPO>(q)
returns a copy of sch
, where
CPO
is either
set_value_t
or
set_stopped_t
. The get_completion_scheduler<set_error_t>
query is not implemented, as the scheduler cannot be guaranteed in case
an error is thrown while trying to schedule work on the given scheduler
object. For all other query objects
Q
whose type satisfies
forwarding-query
, the
expression
Q(q, args...)
shall be
equivalent to
Q(get_env(s), args...)
.[ Editor's note: Update §11.9.6.6 [exec.then] (with analogous changes to §11.9.6.7 [exec.upon.error] and §11.9.6.8 [exec.upon.stopped]) as follows: ]
then
attaches an
invocable as a continuation for an input sender’s value completion
operation.
The name then
denotes a
customization point object. For some subexpressions
s
and
f
, let
S
be
decltype((s))
, let
F
be the decayed type of
f
, and let
be an
xvalue refering to an object decay-copied from
f’f2f
. If
S
does not satisfy
sender
, or
F
does not model
movable-value
,
then(s, f)
is ill-formed. Otherwise, the expression
then(s, f)
is
expression-equivalent to:
transform_sender( get-sender-domain(s), make-then-sender(f, s));
make-then-sender(f, s)
is expression-equivalent to
make-sender(then, f, s)
and returns a sender object s2
that behaves as follows:
tag_invoke(then, get_completion_scheduler<set_value_t>(get_env(s)), s, f)
,
if that expression is valid.
tag_invoke
expression above
satisfies sender
.Otherwise,
tag_invoke(then, s, f)
, if that
expression is valid.
tag_invoke
expression above
satisfies sender
.Otherwise,
constructs a sender
When s2
.s2
is connected with some
receiver out_r
, it:
Constructs a receiver r
such that:
When
set_value(r, args...)
is called,
let v
be the expression invoke(
.
If f’f2, args...)decltype(v)
is
void
, calls
set_value(out_r)
; otherwise, it
calls set_value(out_r, v)
. If
any of these throw an exception, it catches it and calls set_error(out_r, current_exception())
.
If any of these expressions would be ill-formed, the expression
set_value(r, args...)
is
ill-formed.
set_error(r, e)
is
expression-equivalent to
set_error(out_r, e)
.
set_stopped(r)
is
expression-equivalent to
set_stopped(out_r)
.
Returns an expression-equivalent to
connect(s, r)
.
Let
Given subexpressions compl-sig-t<Tag, Args...>
name the type Tag()
if Args...
is a
template paramter pack containing the single type
void
; otherwise,
Tag(Args...)
.s2
and
e
where
s2
is a sender returned from
then
or a copy of such, let
S2
be
decltype((s2))
and let
E
be
decltype((e))
. The type of tag_invoke(get_completion_signatures, s2, e)
shall be equivalent
to:
make_completion_signatures<> copy_cvref_t<S2, S>, E, set-error-signature,
set-value-completions>;
where
set-value-completions
is an alias
forthe alias
template:
template<class... As> set-value-completions =
compl-sig-t<set_value_t,
SET-VALUE-SIG(invoke_result_t<F, As...>)
> completion_signatures<>
and
set-error-signature
is
an alias for completion_signatures<set_error_t(exception_ptr)>
if any of the types in the
type-list
named by
value_types_of_t<copy_cvref_t<S2, S>, E, potentially-throwing, type-list>
are true_type
; otherwise,
completion_signatures<>
,
where
potentially-throwing
is
the template
aliasalias
template:
template<class... As> using potentially-throwing =
bool_constant<!is_nothrow_invocable_v<F, As...>>
negation<is_nothrow_invocable<F, As...>>
;
If the function
selected above Let
S
be the result of
calling then(s, f)
or a copy of such. If
S
is connected with
a recevier R
with
environment E
such
that transform_sender(get-env-domain(E), S, E)
does not return a sender that: [ Editor's note: reformated as a list for
comprehensibility: ]
— invokes f
with the value
result datums of s
,
— usinguses
f
’s return value as the sender’s S
’s
value completion, and
— forwards the non-value completion operations to
R
unchanged,
then the behavior of calling then(s, f)
connect(S, R)
is undefined.
[ Editor's note: Change §11.9.6.9 [exec.let] as follows: ]
let_value
transforms a
sender’s value completion into a new child asynchronous operation.
let_error
transforms a sender’s
error completion into a new child asynchronous operation.
let_stopped
transforms a
sender’s stopped completion into a new child asynchronous
operation.
[ Editor's note:
Copied from below: ] Let the expression
let-cpo
be one of
let_value
,
let_error
, or
let_stopped
and let
set-cpo
be
the completion function that corresponds to
let-cpo
(set_value
for
let_value
, etc.).
For subexpressions
se
and
re
, let
inner-env(se, re)
be an environment e
such that:
—
get_domain(e)
is expression-equivalent to the first well-formed expression below:
get_domain(se)
get_domain(get_completion_scheduler<set-cpo-t>(se))
, whereset-cpo-t
is the type ofset-cpo
.
get-env-domain(re)
—
get_scheduler(e)
is expression-equivalent to the first well-formed expression below:
get_completion_scheduler<set-cpo-t>(se)
get_scheduler(re)
or if neither of them are,
get_scheduler(e)
is ill-formed.— For all other query objects
Q
and argumentsargs...
,Q(E, args...)
is expression-equivalent toQ(RE, args...)
.
The names let_value
,
let_error
, and
let_stopped
denote customization
point objects. Let the
expression
For subexpressions let-cpo
be
one of let_value
,
let_error
, or
let_stopped
.s
and
f
, let
S
be
decltype((s))
, let
F
be the decayed type of
f
, and let
f'
be an xvalue that refers
to an object decay-copied from
f
. If
S
does not satisfy
sender
, the expression
let-cpo(s, f)
is
ill-formed. If F
does not
satisfy invocable
, the
expression let_stopped(s, f)
is
ill-formed. Otherwise, the expression
let-cpo(s, f)
is
expression-equivalent to:
transform_sender( get-sender-domain(s), make-let-sender(f, s));
make-let-sender(f, s)
is expression-equivalent to make-sender(let-cpo, f, s)
and returns a sender object s2
that behaves as follows:
s2
is connected to
some receiver
out_r
,
it:tag_invoke(let-cpo, get_completion_scheduler<set_value_t>(get_env(s)), s, f)
,
if that expression is valid.
tag_invoke
expression above
satisfies sender
.
Otherwise,
tag_invoke(let-cpo, s, f)
,
if that expression is valid.
tag_invoke
expression above
satisfies sender
.
Otherwise, given a receiver
out_r
and an lvalue
out_r'
refering to an object
decay-copied from out_r
.
let_value
, let
set-cpo
be
set_value
. For
let_error
, let
set-cpo
be
set_error
. For
let_stopped
, let
set-cpo
be
set_stopped
. Let
completion-function
be
one of set_value
,
set_error
, or
set_stopped
.
Decay-copies
out_r
intoop_state2
(see below).out_r2
is an xvalue refering to the copy ofout_r
.
LetConstructs a receiverr
be an rvalue of a receiver typeR
r
such that such that:
When
set-cpo(r, args...)
is called, the receiverr
decay-copiesargs...
intoop_state2
asargs'...
, then callsinvoke(f', args'...)
resulting in a senders3
. It then callsconnect(s3,
, resulting in an operation statestd::move(out_r’)out_r3)op_state3
, whereout_r3
is a receiver described below.op_state3
is saved as a part ofop_state2
. It then callsstart(op_state3)
. If any of these throws an exception, it catches it and callsset_error(
. If any of these expressions would be ill-formed,std::move(out_r’)out_r2, current_exception())set-cpo(r, args...)
is ill-formed.
is expression-equivalent to
completion-functionCF(r, args...)completion-function(std::move(out_r'), args...)
whencompletion-function
is different fromset-cpo
CF(out_r2, args...)
, whereCF
is a completion function other thanset-cpo
.get_env(r)
is expression-equivalent toget_env(out_r)
.out_r3
is a receiver that forwards its completion operations toout_r2
and for whichget_env(out_r3)
returnsinner-env(get_env(s), get_env(out_r2))
.
Callslet-cpo(s, f)
returns a senders2
such that:connect(s, r)
resulting in an operation stateop_state2
. [ Editor's note: The formatting is changed here. ] If the expressionconnect(s, r)
is ill-formed,connect(s2, out_r)
is ill-formed.
Otherwise, letReturns an operation stateop_state2
be the result ofconnect(s, r)
.connect(s2, out_r)
returnsop_state
that storesop_state2
.start(op_state)
is expression-equivalent tostart(op_state2)
.
Given subexpressions s2
and e
, where
s2
is a sender returned from
let-cpo(s, f)
or a copy
of such, let S2
be
decltype((s2))
, let
E
be
decltype((e))
, and let
DS
be
copy_cvref_t<S2, S>
. Then
the type of tag_invoke(get_completion_signatures, s2, e)
is specified as follows:
If sender_in<DS, E>
is false
, the expression tag_invoke(get_completion_signatures, s2, e)
is ill-formed.
Otherwise, let Sigs...
be
the set of template arguments of the
completion_signatures
specialization named by completion_signatures_of_t<DS, E>
,
let Sigs2...
be the set of
function types in Sigs...
whose
return type is set-cpo
,
and let Rest...
be the set of
function types in Sigs...
but
not Sigs2...
.
For each
Sig2i
in
Sigs2...
, let Vsi...
be the set
of function arguments in
Sig2i
and
let S3i
be
invoke_result_t<F, decay_t<Vsi>&...>
.
If S3i
is
ill-formed, or if
get-sender-domain(declval<S3i>())
has a different type than
get-sender-domain(s)
,
or if sender_in<S3i,
is
not satisfied where
EE2>E2
is the type of
inner-env(get_env(s), e)
,
then the expression tag_invoke(get_completion_signatures, s2, e)
is ill-formed.
Otherwise, let Sigs3i...
be the
set of template arguments of the
completion_signatures
specialization named by completion_signatures_of_t<S3i,
. Then
the type of EE2>tag_invoke(get_completion_signatures, s2, e)
shall be equivalent to completion_signatures<Sigs30..., Sigs31...,
... Sigs3n-1..., Rest..., set_error_t(exception_ptr)>
,
where n
is
sizeof...(Sigs2)
.
s
and
e
be subexpressions such that
S
is
decltype((s))
and
E
is
decltype((e))
. If sender-for<S, let-cpo-t>
is false
where
let-cpo-t
is the type
of let-cpo
, then the
expression let-cpo-t().transform_env(s, e)
is ill-formed. Otherwise, it is equal to
inner-env(get_env(s), e)
.If a sender
S
returned
from
let-cpo(s, f)
is connected to a receiver
R
with environment
E
such that
transform_sender(get-env-domain(E), S, E)
does not return a sender that [ Editor's note: reformated as a list for
comprehensibility ]:
— invokes f
when
set-cpo
is called with
s
’s result
datums, and
— makes its completion dependent on the completion of a sender
returned by f
, and
— propagates the other completion operations sent by
s
,
the behavior of calling let-cpo(s, f)
connect(S, R)
is undefined.
[ Editor's note: Change §11.9.6.10 [exec.bulk] as follows: ]
bulk
runs a task
repeatedly for every index in an index space.
The name bulk
denotes a
customization point object. For some subexpressions
s
,
shape
, and
f
, let
S
be
decltype((s))
,
Shape
be
decltype((shape))
, and
F
be
decltype((f))
. If
S
does not satisfy
sender
or
Shape
does not satisfy
integral
,
bulk
is ill-formed. Otherwise,
the expression bulk(s, shape, f)
is expression-equivalent to:
transform_sender( get-sender-domain(s), make-bulk-sender(tuple-like{shape, f}, s));
where
make-bulk-sender(t, s)
is expression-equivalent to
make-sender(bulk, t, s)
for a subexpression t
and
returns a sender object s2
that
behaves as follows:
tag_invoke(bulk, get_completion_scheduler<set_value_t>(get_env(s)), s, shape, f)
,
if that expression is valid.
tag_invoke
expression above
satisfies sender
.
Otherwise,
tag_invoke(bulk, s, shape, f)
,
if that expression is valid.
tag_invoke
expression above
satisfies sender
.
Otherwise,
constructs a sender
When s2
.s2
is connected with some
receiver out_r
, it:
Constructs a receiver
r
:
When
set_value(r, args...)
is called,
calls f(i, args...)
for each
i
of type
Shape
from
0
to
shape
, then calls
set_value(out_r, args...)
. If
any of these throws an exception, it catches it and calls set_error(out_r, current_exception())
.
If any of these
expressions are ill-formed,
set_value(r, args...)
is ill-formed.
When set_error(r, e)
is
called, calls
set_error(out_r, e)
.
When set_stopped(r)
is
called, calls
set_stopped(out_r, e)
.
Calls connect(s, r)
,
which results in an operation state
op_state2
.
Returns an operation state
op_state
that contains
op_state2
. When
start(op_state)
is called, calls
start(op_state2)
.
Given subexpressions s2
and e
where
s2
is a sender returned from
bulk
or a copy of such, let
S2
be
decltype((s2))
, let
E
be
decltype((e))
, let
DS
be
copy_cvref_t<S2, S>
, let
Shape
be
decltype((shape))
and let
nothrow-callable
be the
alias template:
template<class... As> using nothrow-callable = bool_constant<is_nothrow_invocable_v<decay_t<F>&, Shape, As...>>;
If any of the types in the
type-list
named by
value_types_of_t<DS, E, nothrow-callable, type-list>
are false_type
, then the type of
tag_invoke(get_completion_signatures, s2, e)
shall be equivalent
to:
make_completion_signatures< DS, E, completion_signatures<set_error_t(exception_ptr)>>
Otherwise, the type of tag_invoke(get_completion_signatures, s2, e)
shall be equivalent
to completion_signatures_of_t<DS, E>
.
If the function
selected above Let
S
be the result of
calling
bulk(s, shape, f)
or a copy of such. If
S
is connected to a
receiver R
with
environment E
such
that transform_sender(get-env-domain(E), S, E)
does not return a sender that invokes
f(i, args...)
for each
i
of type
Shape
from
0
to
shape
where
args
is a pack of subexpressions
refering to the value completion result datums of the input sender, or
does not execute a value completion operation with said datums, the
behavior of calling bulk(s, shape, f)
connect(S, R)
is undefined.
[ Editor's note: Change §11.9.6.11 [exec.split] as follows: ]
split
adapts an arbitrary
sender into a sender that can be connected multiple times.
Let split-env
be
the type of an environment such that, given an instance
e
, the expression
get_stop_token(e)
is well-formed
and has type
stop_token
.
The name split
denotes a
customization point object. For some subexpression
s
, let
S
be
decltype((s))
. If sender_in<S, split-env>
or constructible_from<decay_t<env_of_t<S>>, env_of_t<S>>
is false
,
split
is ill-formed. Otherwise,
the expression split(s)
is
expression-equivalent to:
transform_sender( get-sender-domain(s), make-sender(split, s));
tag_invoke(split, get_completion_scheduler<set_value_t>(get_env(s)), s)
,
if that expression is valid.
Mandates: The type of the
tag_invoke
expression above
satisfies sender
.
Otherwise,
tag_invoke(split, s)
, if that
expression is valid.
Mandates: The type of the
tag_invoke
expression above
satisfies sender
.
Let
s
be a
subexpression such that
S
is
decltype((s))
, and
let e...
be a pack
of subexpressions such that
sizeof...(e) <= 1
is true
. If
sender-for<S, split_t>
is false
, then the
expression split_t().transform_sender(s, e...)
is ill-formed; otherwise, it returns Otherwise, constructs a sender
s2
, whichthat:
sh_state
that [ Editor's note: … as
before ][Change §11.9.6.12 [exec.when.all] as follows:]
when_all
and
when_all_with_variant
both adapt
multiple input senders into a sender that completes when all input
senders have completed. when_all
only accepts senders with a single value completion signature and on
success concatenates all the input senders’ value result datums into its
own value completion operation.
when_all_with_variant(s...)
is
semantically equivilant to
when_all(into_variant(s)...)
,
where s
is a pack of
subexpressions of sender types.
The names
when_all
and
when_all_with_variant
denotes a customization
point objects. For some subexpressions
si...
, let
Si...
be
decltype((si))...
.
The expressions when_all(si...)
is and when_all_with_variant(si...)
are ill-formed if any of the following is true:
If the number of subexpressions
si...
is 0,
or
If any type
Si
does not
satisfy sender
.
If the expression
get-sender-domain(si)
has a different type for any other value of
i
.
Otherwise, those expressions have the semantics specified below.
[ Editor's note: The following paragraph becomes numbered and subsequent paragraphs are renumbered. ]
Otherwise,
theThe expression when_all(si...)
is
expression-equivalent to:
transform_sender( get-sender-domain(s0), make-when-all-sender(s0, ... sn-1))
where make-when-all-sender(si...)
is expression-equivalent to make-sender(when_all, unspecified, si...)
and returns a sender object
w
of type
W
that behaves as
follows:
tag_invoke(when_all, si...)
,
if that expression is valid. If the function selected by
tag_invoke
does not return a
sender that sends a concatenation of values sent by
si...
when
they all complete with
set_value
, the behavior of
calling when_all(si...)
is
undefined.
tag_invoke
expression above
satisfies sender
.
Otherwise,
constructs a sender
When w
of type
W
.w
is connected with some
receiver out_r
of type
OutR
, it returns an operation
state op_state
specified as
below:
si
, … [ Editor's note: … as before
]…
The name
The expression when_all_with_variant
denotes a customization point object. For some subexpressions
s...
, let
S
be
decltype((s))
. If
any type
Si
in S...
does not
satisfy sender
,
when_all_with_variant
is ill-formed. Otherwise, thewhen_all_with_variant(si...)
is expression-equivalent to:
transform_sender( get-sender-domain(s0), make-sender(when_all_with_variant, unspecified, s0, ... sn-1))
tag_invoke(when_all_with_variant, s...)
, if that expression is valid. If the function selected bytag_invoke
does not return a sender that, when connected with a receiver of typeR
, sends the typesinto-variant-type<S, env_of_t<R>>...
when they all complete withset_value
, the behavior of callingwhen_all(si...)
is undefined.
- Mandates: The type of the
tag_invoke
expression above satisfiessender
.Otherwise,
when_all(into_variant(s)...)
.
Let s
and
e
be subexpressions such that
S
is
decltype((s))
. If sender-for<S, when_all_with_variant_t>
is false
, then the expression
when_all_with_variant_t().transform_sender(s, e)
is ill-formed; otherwise, it is equal to:
const auto& env = e; auto domain = get-env-domain(env); auto [tag, data, ...child] = s; auto tfx = make-transformer-fn(domain, env); return tfx(when_all)(tfx(into_variant)(std::move(child))...);
[ Note: This causes the
when_all_with_variant(s...)
sender to become
when_all(into_variant(s)...)
when it is connected with a receiver whose execution domain does not
customize
when_all_with_variant
. —
end note ]
s2
returned from
when_all
or
when_all_with_variant
,
get_env(s2)
shall
return an instance of a class equivalent to
empty_env
.s...
, let
S
be an object
returned from
when_all(s...)
or
when_all_with_variant(s...)
or a copy of such, and let
E
be the
environment object returned from
get_env(S)
. Given a
query object Q
,
tag_invoke(Q, E)
is
expression-equivalent to get-sender-domain(s0)
when Q
is
get_domain
;
otherwise, it is ill-formed.[ Editor's note: Change §11.9.6.13 [exec.transfer.when.all] as follows: ]
transfer_when_all
and
transfer_when_all_with_variant
both adapt multiple input senders into a sender that completes when all
input senders have completed, ensuring the input senders complete on the
specified scheduler.
transfer_when_all
only accepts
senders with a single value completion signature and on success
concatenates all the input senders’ value result datums into its own
value completion operation; transfer_when_all(scheduler, input-senders...)
is semantically equivalent to transfer(when_all(input-senders...), scheduler)
.
transfer_when_all_with_variant(scheduler, input-senders...)
is semantically equivilant to transfer_when_all(scheduler, into_variant(intput-senders)...)
.
[ Note: These customizable
composite algorithms can allow for more efficient customizations in some
cases. — end note ]
The name
transfer_when_all
denotes a
customization point object. For some subexpressions
sch
and
s...
, let
Sch
be
decltype(sch)
and
S
be
decltype((s))
. If
Sch
does not satisfy
scheduler
, or any type
Si
in
S...
does not satisfy
sender
,
transfer_when_all
is ill-formed.
Otherwise, the expression
transfer_when_all(sch, s...)
is
expression-equivalent to:
return transform_sender( query-or-default(get_domain, sch, default_domain()), make-sender(transfer_when_all, sch, s...));
tag_invoke(transfer_when_all, sch, s...)
, if that expression is valid. If the function selected bytag_invoke
does not return a sender that sends a concatenation of values sent bys...
when they all complete withset_value
, or does not send its completion operation, other than ones resulting from a scheduling error, on an execution agent belonging to the associated execution resource ofsch
, the behavior of callingtransfer_when_all(sch, s...)
is undefined.
- Mandates: The type of the
tag_invoke
expression above satisfiessender
.Otherwise,
transfer(when_all(s...), sch)
.
Let s
and
e
be subexpressions such that
S
is
decltype((s))
. If sender-for<S, transfer_when_all_t>
is false
, then the expression
transfer_when_all_t().transform_sender(s, e)
is ill-formed; otherwise, it is equal to:
const auto& env = e; auto domain = get-env-domain(env); auto [tag, data, ...child] = s; auto tfx = make-transformer-fn(domain, env); return tfx(transfer)(tfx(when_all)(std::move(child)...), std::move(data));
[ Note: This causes the
transfer_when_all(sch, s...)
sender to become
transfer(when_all(s...), sch)
when it is connected with a receiver whose execution domain does not
customize
transfer_when_all
. —
end note ]
The name
transfer_when_all_with_variant
denotes a customization point object. For some subexpressions
sch
and
s...
, let
Sch
be
decltype((sch))
and let
S
be
decltype((s))
. If any type
Si
in
S...
does not satisfy
sender
,
transfer_when_all_with_variant
is ill-formed. Otherwise, the expression transfer_when_all_with_variant(sch, s...)
is expression-equivalent to:
return transform_sender( query-or-default(get_domain, sch, default_domain()), make-sender(transfer_when_all_with_variant, sch, s...));
tag_invoke(transfer_when_all_with_variant, s...)
, if that expression is valid. If the function selected bytag_invoke
does not return a sender that, when connected with a receiver of typeR
, sends the typesinto-variant-type<S, env_of_t<R>>...
when they all complete withset_value
, the behavior of callingtransfer_when_all_with_variant(sch, s...)
is undefined.
- Mandates: The type of the
tag_invoke
expression above satisfiessender
.Otherwise,
transfer_when_all(sch, into_variant(s)...)
.
Let s
and
e
be subexpressions such that
S
is
decltype((s))
. If sender-for<S, transfer_when_all_with_variantt>
is false
, then the expression
transfer_when_all_with_variant_t().transform_sender(s, e)
is ill-formed; otherwise, it is equal to:
const auto& env = e; auto domain = get-env-domain(env); auto [tag, data, ...child] = s; auto tfx = make-transformer-fn(domain, env); return tfx(transfer_when_all)(std::move(data), tfx(into_variant)(std::move(child))...);
[ Note: This causes the
transfer_when_all_with_variant(sch, s...)
sender to become transfer_when_all(sch, into_variant(s)...)
when it is connected with a receiver whose execution domain does not
customize
transfer_when_all_with_variant
.
— end note ]
t
returned from
transfer_when_all(sch, s...)
or transfer_when_all_with_variant(sch, s...)
,
get_env(t)
shall return a
queryable object q
such that
get_domain(q)
shall be expression-equivalent to
get_domain(sch)
,
and get_completion_scheduler<CPO>(q)
returns a copy of sch
, where
CPO
is either
set_value_t
or
set_stopped_t
. The get_completion_scheduler<set_error_t>
query is not implemented, as the scheduler cannot be guaranteed in case
an error is thrown while trying to schedule work on the given scheduler
object.[ Editor's note: Change §11.9.6.14 [exec.into.variant] as follows: ]
into_variant
adapts a
sender with multiple value completion signatures into a sender with just
one consisting of a variant
of
tuple
s.
The template
into-variant-type
computes the type sent by a sender returned from
into_variant
.
template<class S, class E> requires sender_in<S, E> using into-variant-type = value_types_of_t<S, E>;
into_variant
is a
customization point object. For some subexpression
s
, let
S
be
decltype((s))
. If
S
does not satisfy
sender
,
into_variant(s)
is ill-formed.
Otherwise, into_variant(s)
is expression-equivalent
to:
transform_sender( get-sender-domain(s), make-into-variant-sender(s))
where
make-into-variant-sender(s)
is expression-equivalent to make-sender(into_variant, unspecified, s)
and returns a sender object
s2
. that behaves as follows:
[ Editor's note: Reformatting here ]
When s2
is connected with
some receiver out_r
,
it:
Constructs a receiver
r
:
If set_value(r, ts...)
is
called, calls set_value(out_r, into-variant-type<S, env_of_t<decltype((r))>>(decayed-tuple<decltype(ts)...>(ts...)))
.
If this expression throws an exception, calls set_error(out_r, current_exception())
.
set_error(r, e)
is
expression-equivalent to
set_error(out_r, e)
.
set_stopped(r)
is
expression-equivalent to
set_stopped(out_r)
.
Calls connect(s, r)
,
resulting in an operation state
op_state2
.
Returns an operation state
op_state
that contains
op_state2
. When
start(op_state)
is called, calls
start(op_state2)
.
Given subexpressions s2
and e
[…] [ Editor's note: …as before ]
[ Editor's note: Change §11.9.6.15 [exec.stopped.as.optional] as follows: ]
stopped_as_optional
maps
an input sender’s stopped completion operation into the value completion
operation as an empty optional. The input sender’s value completion
operation is also converted into an optional. The result is a sender
that never completes with stopped, reporting cancellation by completing
with an empty optional.
The name
stopped_as_optional
denotes a
customization point object. For some subexpression
s
, let
S
be
decltype((s))
. Let
The expression
_get-env-sender_
be
an expression such that, when it is
connect
ed with a
receiver r
,
start
on the
resulting operation state completes immediately by calling
set_value(r, get_env(r))
.stopped_as_optional(s)
is
expression-equivalent to:
transform_sender( get-sender-domain(s), make-sender(stopped_as_optional, unspecified, s))
let_value( get-env-sender, []<class E>(const E&) requires single-sender<S, E> { return let_stopped( then(s, []<class T>(T&& t) { return optional<decay_t<single-sender-value-type<S, E>>>{ std::forward<T>(t) }; } ), [] () noexcept { return just(optional<decay_t<single-sender-value-type<S, E>>>{}); } ); } )
Let s
and
e
be subexpressions such that
S
is
decltype((s))
and
E
is
decltype((e))
. If either sender-for<S, stopped_as_optional_t>
or
single-sender<S, E>
is false
, then the expression
stopped_as_optional_t().transform_sender(s, e)
is ill-formed; otherwise, it is equal to:
const auto& env = e; auto domain = get-env-domain(env); auto [tag, data, child] = s; using V = single-sender-value-type<S, E>; auto tfx = make-transformer-fn(domain, env); return tfx(let_stopped)( tfx(then)(std::move(child), []<class T>(T&& t) { return optional<V>(std::forward<T>(t)); }), []() noexcept { return just(optional<V>()); });
[ Editor's note: Change §11.9.6.16 [exec.stopped.as.error] as follows: ]
stopped_as_error
maps an
input sender’s stopped completion operation into an error completion
operation as a custom error type. The result is a sender that never
completes with stopped, reporting cancellation by completing with an
error.
The name stopped_as_error
denotes a customization point object. For some subexpressions
s
and
e
, let
S
be
decltype((s))
and let
E
be
decltype((e))
. If the type
S
does not satisfy
sender
or if the type
E
doesn’t satisfy
movable-value
,
stopped_as_error(s, e)
is
ill-formed. Otherwise, the expression
stopped_as_error(s, e)
is
expression-equivalent to:
let_stopped(s, [] { return just_error(e); })
transform_sender( get-sender-domain(s), make-sender(stopped_as_error, e, s))
Let s
and
e
be subexpressions such that
S
is
decltype((s))
and
E
is
decltype((e))
. If sender-for<S, stopped_as_error_t>
is false
, then the expression
stopped_as_error_t().transform_sender(s, e)
is ill-formed; otherwise, it is equal to:
const auto& env = e; auto domain = get-env-domain(env); auto [tag, data, child] = s; auto tfx = make-transformer-fn(domain, env); return tfx(let_stopped)( std::move(child), [err = std::move(data)]() mutable { return just_error(std::move(err)); });
[ Editor's note: Change §11.9.6.17 [exec.ensure.started] as follows: ]
ensure_started
eagerly
starts the execution of a sender, returning a sender that is usable as
intput to additional sender algorithms.
Let
ensure-started-env
be
the type of an execution environment such that, given an instance
e
, the expression
get_stop_token(e)
is well-formed
and has type
stop_token
.
The name ensure_started
denotes a customization point object. For some subexpression
s
, let
S
be
decltype((s))
. If sender_in<S, ensure-started-env>
or constructible_from<decay_t<env_of_t<S>>, env_of_t<S>>
is false
,
ensure_started(s)
is ill-formed.
Otherwise, the expression
ensure_started(s)
is
expression-equivalent to:
transform_sender( get-sender-domain(s), make-sender(ensure_started, s));
tag_invoke(ensure_started, get_completion_scheduler<set_value_t>(get_env(s)), s)
, if that expression is valid.
- Mandates: The type of the
tag_invoke
expression above satisfiessender
.Otherwise,
tag_invoke(ensure_started, s)
, if that expression is valid.
- Mandates: The type of the
tag_invoke
expression above satisfiessender
.
Let
s
be a subexpression such thatS
isdecltype((s))
, and lete...
be a pack of subexpressions such thatsizeof...(e) <= 1
istrue
. Ifsender-for<S, ensure_started_t>
isfalse
, then the expressionensure_started_t().transform_sender(s, e...)
is ill-formed; otherwise, it returnsOtherwise, constructsa senders2
, whichthat:
- Creates an object
sh_state
that [ Editor's note: … as before ]
[ Editor's note: Change §11.9.7.1 [exec.start.detached] as follows: ]
start_detached
eagerly
starts a sender without the caller needing to manage the lifetimes of
any objects.
The name start_detached
denotes a customization point object. For some subexpression
s
, let
S
be
decltype((s))
. If
S
does not satisfy sender
sender_in<empty_env>
,
start_detached
is ill-formed.
Otherwise, the expression
start_detached(s)
is
expression-equivalent to:
apply_sender(get-sender-domain(s), start_detached, s)
- Mandates: The type of the expression above is
void
.
If the
function selectedexpression above does not eagerly start the senders
after connecting it with a receiver that ignores value and stopped completion operations and callsterminate()
on error completions, the behavior of callingstart_detached(s)
is undefined.
tag_invoke(start_detached, get_completion_scheduler<set_value_t>(get_env(s)), s)
, if that expression is valid.
- Mandates: The type of the
tag_invoke
expression above isvoid
.Otherwise,
tag_invoke(start_detached, s)
, if that expression is valid.
- Mandates: The type of the
tag_invoke
expression above isvoid
.Otherwise, let
R
be the type of a receiver, letr
be an rvalue of typeR
, and letcr
be a lvalue reference toconst R
such that:— The expression
set_value(r)
is not potentially-throwing and has no effect,— For any subexpression
e
, the expressionset_error(r, e)
is expression-equivalent toterminate()
,— The expression
set_stopped(r)
is not potentially-throwing and has no effect, and— The expression
get_env(cr)
is expression-equivalent toempty_env{}
.Calls
connect(s, r)
, resulting in an operation stateop_state
, then callsstart(op_state)
.
Let s
be a subexpression
such that S
is
decltype((s))
, and let
detached-receiver
and
detached-operation
be
the following exposition-only class types:
struct detached-receiver { using is_receiver = unspecified; detached-operation* op; // exposition only friend void tag_invoke(set_value_t, detached-receiver&& self) noexcept { delete self.op; } friend void tag_invoke(set_error_t, detached-receiver&&, auto&&) noexcept { terminate(); } friend void tag_invoke(set_stopped_t, detached-receiver&& self) noexcept { delete self.op; } friend empty_env tag_invoke(get_env_t, const detached-receiver&) noexcept { return {}; } }; struct detached-operation { connect_result_t<S, detached-receiver> op; // exposition only explicit detached-operation(S&& s) : op(connect(std::forward<S>(s), detached-receiver{this})) {} };
If sender_to<S, detached-receiver>
is false
, then the expression
start_detached_t().apply_sender(s)
is
ill-formed; otherwise, it is expression-equivalent to:
start((new detached-operation(s))->op)
[ Editor's note: Change §11.9.7.2 [exec.sync.wait] as follows: ]
this_thread::sync_wait
denotes a
customization point object. For some subexpression
s
, let
S
be
decltype((s))
. If sender_in<S, sync-wait-env>
is false
, or completion_signatures_of_t<S, sync-wait-env>::value_types
passed into the
Variant
template
parameter is not 1completion_signatures_of_t<S, sync-wait-env, type-list, type_identity_t>
is ill-formed,
this_thread::sync_wait(s)
is
ill-formed. Otherwise,
this_thread::sync_wait(s)
is
expression-equivalent to:apply_sender(get-sender-domain(s), sync_wait, s)
- Mandates: The type of expression above is
sync-wait-type<S, sync-wait-env>
.
tag_invoke(this_thread::sync_wait, get_completion_scheduler<set_value_t>(get_env(s)), s)
, if this expression is valid.
- Mandates: The type of the
tag_invoke
expression above issync-wait-type<S, sync-wait-env>
.Otherwise,
tag_invoke(this_thread::sync_wait, s)
, if this expression is valid and its type is.
- Mandates: The type of the
tag_invoke
expression above issync-wait-type<S, sync-wait-env>
.
Otherwise: Let
sync-wait-receiver
be a class type that satisfies
receiver
, let
r
be an xvalue of
that type, and let
cr
be a const
lvalue refering to
r
such that
get_env(cr)
has
type
sync-wait-env
.
If sender_in<S, sync-wait-env>
is false
, or if the
type completion_signatures_of_t<S, sync-wait-env, type-list, type_identity_t>
is ill-formed, the expression
sync_wait_t().apply_sender(s)
is ill-formed; otherwise, it has the following effects:
Constructs a
receiver
r
.
Calls connect(s, r)
,
resulting in an operation state
op_state
, then calls
start(op_state)
.
Blocks the current thread until a completion operation of
r
is executed. When it is:
If set_value(r, ts...)
has been called, returns sync-wait-type<S, sync-wait-env>{decayed-tuple<decltype(ts)...>{ts...}}
.
If that expression exits exceptionally, the exception is propagated to
the caller of
sync_wait
.
If set_error(r, e)
has
been called, let E
be the
decayed type of e
. If
E
is
exception_ptr
, calls
std::rethrow_exception(e)
.
Otherwise, if the E
is
error_code
, throws
system_error(e)
. Otherwise,
throws e
.
If set_stopped(r)
has
been called, returns sync-wait-type<S, sync-wait-env>{}
.
The name this_thread::sync_wait_with_variant
denotes a customization point object. For some subexpression
s
, let
S
be the type of
into_variant(s)
. If sender_in<S, sync-wait-env>
is false
, this_thread::sync_wait_with_variant(s)
is ill-formed. Otherwise, this_thread::sync_wait_with_variant(s)
is expression-equivalent to:
apply_sender(get-sender-domain(s), sync_wait_with_variant, s)
- Mandates: The type of expression above is
sync-wait-with-variant-type<S, sync-wait-env>
.
tag_invoke(this_thread::sync_wait_with_variant, get_completion_scheduler<set_value_t>(get_env(s)), s)
, if this expression is valid.
- Mandates: The type of the
tag_invoke
expression above issync-wait-with-variant-type<S, sync-wait-env>
.Otherwise,
tag_invoke(this_thread::sync_wait_with_variant, s)
, if this expression is valid.
- Mandates: The type of the
tag_invoke
expression above issync-wait-with-variant-type<S, sync-wait-env>
.
sync_wait_with_variant_t().apply_sender(s)
is expression-equivalent to this_thread::sync_wait(into_variant(s))
.[Update §11.10 [exec.execute] as follows:]
execute
creates
fire-and-forget tasks on a specified scheduler.
The name execute
denotes
a customization point object. For some subexpressions
sch
and
f
, let
Sch
be
decltype((sch))
and
F
be
decltype((f))
. If
Sch
does not satisfy
scheduler
or
F
does not satisfy
invocable
,
execute
is ill-formed.
Otherwise, execute
is
expression-equivalent to:
apply_sender( query-or-default(get_domain, sch, default_domain()), execute, schedule(sch), f)
- Mandates: The type of the expression above is
void
.
tag_invoke(execute, sch, f)
, if that expression is valid. If the function selected bytag_invoke
does not invoke the functionf
(or an object decay-copied fromf
) on an execution agent belonging to the associated execution resource ofsch
, or if it does not callstd::terminate
if an error occurs after control is returned to the caller, the behavior of callingexecute
is undefined.
- Mandates: The type of the
tag_invoke
expression above isvoid
.
s
and
f
where
F
is
decltype((f))
, if
F
does not satisfy
invocable
, the
expression
execute_t().apply_sender(s, f)
is ill-formed; otherwise, it is expression-equivalent to
start_detached(then(schedule(sch)s, f))
.std::execution
.