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

326 lines
15 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[exec.queries]
# 33 Execution control library [[exec]](./#exec)
## 33.5 Queries [exec.queries]
### [33.5.1](#exec.fwd.env) forwarding_query [[exec.fwd.env]](exec.fwd.env)
[1](#exec.fwd.env-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L837)
forwarding_query asks a query object
whether it should be forwarded through queryable adaptors[.](#exec.fwd.env-1.sentence-1)
[2](#exec.fwd.env-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L841)
The name forwarding_query denotes a query object[.](#exec.fwd.env-2.sentence-1)
For some query object q of type Q,forwarding_query(q) is expression-equivalent to:
- [(2.1)](#exec.fwd.env-2.1)
*MANDATE-NOTHROW*(q.query(forwarding_query)) if that expression is well-formed[.](#exec.fwd.env-2.1.sentence-1)
*Mandates*: The expression above has type bool and
is a core constant expression if q is a core constant expression[.](#exec.fwd.env-2.1.sentence-2)
- [(2.2)](#exec.fwd.env-2.2)
Otherwise, true if [derived_from](concept.derived#concept:derived_from "18.4.3Concept derived_­from[concept.derived]")<Q, forwarding_query_t> is true[.](#exec.fwd.env-2.2.sentence-1)
- [(2.3)](#exec.fwd.env-2.3)
Otherwise, false[.](#exec.fwd.env-2.3.sentence-1)
### [33.5.2](#exec.get.allocator) get_allocator [[exec.get.allocator]](exec.get.allocator)
[1](#exec.get.allocator-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L861)
get_allocator asks a queryable object for its associated allocator[.](#exec.get.allocator-1.sentence-1)
[2](#exec.get.allocator-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L864)
The name get_allocator denotes a query object[.](#exec.get.allocator-2.sentence-1)
For a subexpression env,get_allocator(env) is expression-equivalent to*MANDATE-NOTHROW*(*AS-CONST*(env).query(get_allocator))[.](#exec.get.allocator-2.sentence-2)
*Mandates*: If the expression above is well-formed,
its type satisfies[*simple-allocator*](allocator.requirements.general#concept:simple-allocator "16.4.4.6.1General[allocator.requirements.general]") ([[allocator.requirements.general]](allocator.requirements.general "16.4.4.6.1General"))[.](#exec.get.allocator-2.sentence-3)
[3](#exec.get.allocator-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L875)
forwarding_query(get_allocator) is a core constant expression and
has value true[.](#exec.get.allocator-3.sentence-1)
### [33.5.3](#exec.get.stop.token) get_stop_token [[exec.get.stop.token]](exec.get.stop.token)
[1](#exec.get.stop.token-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L881)
get_stop_token asks a queryable object for an associated stop token[.](#exec.get.stop.token-1.sentence-1)
[2](#exec.get.stop.token-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L884)
The name get_stop_token denotes a query object[.](#exec.get.stop.token-2.sentence-1)
For a subexpression env,get_stop_token(env) is expression-equivalent to:
- [(2.1)](#exec.get.stop.token-2.1)
*MANDATE-NOTHROW*(*AS-CONST*(env).query(get_stop_token)) if that expression is well-formed[.](#exec.get.stop.token-2.1.sentence-1)
*Mandates*: The type of the expression above satisfies [stoppable_token](stoptoken.concepts#concept:stoppable_token "32.3.3Stop token concepts[stoptoken.concepts]")[.](#exec.get.stop.token-2.1.sentence-2)
- [(2.2)](#exec.get.stop.token-2.2)
Otherwise, never_stop_token{}[.](#exec.get.stop.token-2.2.sentence-1)
[3](#exec.get.stop.token-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L900)
forwarding_query(get_stop_token) is a core constant expression and
has value true[.](#exec.get.stop.token-3.sentence-1)
### [33.5.4](#exec.get.env) execution::get_env [[exec.get.env]](exec.get.env)
[1](#exec.get.env-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L906)
execution::get_env is a customization point object[.](#exec.get.env-1.sentence-1)
For a subexpression o,execution::get_env(o) is expression-equivalent to:
- [(1.1)](#exec.get.env-1.1)
*MANDATE-NOTHROW*(*AS-CONST*(o).get_env()) if that expression is well-formed[.](#exec.get.env-1.1.sentence-1)
*Mandates*: The type of the expression above satisfies[*queryable*](exec.queryable.concept#concept:queryable "33.2.2queryable concept[exec.queryable.concept]") ([[exec.queryable]](exec.queryable "33.2Queries and queryables"))[.](#exec.get.env-1.1.sentence-2)
- [(1.2)](#exec.get.env-1.2)
Otherwise, env<>{}[.](#exec.get.env-1.2.sentence-1)
[2](#exec.get.env-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L922)
The value of get_env(o) shall be valid while o is valid[.](#exec.get.env-2.sentence-1)
[3](#exec.get.env-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L925)
[*Note [1](#exec.get.env-note-1)*:
When passed a sender object,get_env returns the sender's associated attributes[.](#exec.get.env-3.sentence-1)
When passed a receiver,get_env returns the receiver's associated execution environment[.](#exec.get.env-3.sentence-2)
— *end note*]
### [33.5.5](#exec.get.domain) execution::get_domain [[exec.get.domain]](exec.get.domain)
[1](#exec.get.domain-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L935)
get_domain asks a queryable object
for its associated execution domain tag[.](#exec.get.domain-1.sentence-1)
[2](#exec.get.domain-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L939)
The name get_domain denotes a query object[.](#exec.get.domain-2.sentence-1)
For a subexpression env,get_domain(env) is expression-equivalent to*MANDATE-NOTHROW*(*AS-CONST*(env).query(get_domain))[.](#exec.get.domain-2.sentence-2)
[3](#exec.get.domain-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L945)
forwarding_query(execution::get_domain) is
a core constant expression and has value true[.](#exec.get.domain-3.sentence-1)
### [33.5.6](#exec.get.scheduler) execution::get_scheduler [[exec.get.scheduler]](exec.get.scheduler)
[1](#exec.get.scheduler-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L951)
get_scheduler asks a queryable object for its associated scheduler[.](#exec.get.scheduler-1.sentence-1)
[2](#exec.get.scheduler-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L954)
The name get_scheduler denotes a query object[.](#exec.get.scheduler-2.sentence-1)
For a subexpression env,get_scheduler(env) is expression-equivalent to*MANDATE-NOTHROW*(*AS-CONST*(env).query(get_scheduler))[.](#exec.get.scheduler-2.sentence-2)
*Mandates*: If the expression above is well-formed,
its type satisfies [scheduler](exec.sched#concept:scheduler "33.6Schedulers[exec.sched]")[.](#exec.get.scheduler-2.sentence-3)
[3](#exec.get.scheduler-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L964)
forwarding_query(execution::get_scheduler) is
a core constant expression and has value true[.](#exec.get.scheduler-3.sentence-1)
### [33.5.7](#exec.get.delegation.scheduler) execution::get_delegation_scheduler [[exec.get.delegation.scheduler]](exec.get.delegation.scheduler)
[1](#exec.get.delegation.scheduler-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L970)
get_delegation_scheduler asks a queryable object for a scheduler
that can be used to delegate work to
for the purpose of forward progress delegation ([[intro.progress]](intro.progress "6.10.2.3Forward progress"))[.](#exec.get.delegation.scheduler-1.sentence-1)
[2](#exec.get.delegation.scheduler-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L975)
The name get_delegation_scheduler denotes a query object[.](#exec.get.delegation.scheduler-2.sentence-1)
For a subexpression env,get_delegation_scheduler(env) is expression-equivalent to*MANDATE-NOTHROW*(*AS-CONST*(env).query(get_delegation_scheduler))[.](#exec.get.delegation.scheduler-2.sentence-2)
*Mandates*: If the expression above is well-formed,
its type satisfies [scheduler](exec.sched#concept:scheduler "33.6Schedulers[exec.sched]")[.](#exec.get.delegation.scheduler-2.sentence-3)
[3](#exec.get.delegation.scheduler-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L985)
forwarding_query(execution::get_delegation_scheduler) is
a core constant expression and has value true[.](#exec.get.delegation.scheduler-3.sentence-1)
### [33.5.8](#exec.get.fwd.progress) execution::get_forward_progress_guarantee [[exec.get.fwd.progress]](exec.get.fwd.progress)
namespace std::execution {enum class [forward_progress_guarantee](#lib:forward_progress_guarantee "33.5.8execution::get_­forward_­progress_­guarantee[exec.get.fwd.progress]") { concurrent,
parallel,
weakly_parallel };}
[1](#exec.get.fwd.progress-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L1001)
get_forward_progress_guarantee asks a scheduler about
the forward progress guarantee of execution agents
created by that scheduler's associated execution resource ([[intro.progress]](intro.progress "6.10.2.3Forward progress"))[.](#exec.get.fwd.progress-1.sentence-1)
[2](#exec.get.fwd.progress-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L1006)
The name get_forward_progress_guarantee denotes a query object[.](#exec.get.fwd.progress-2.sentence-1)
For a subexpression sch, let Sch be decltype((sch))[.](#exec.get.fwd.progress-2.sentence-2)
If Sch does not satisfy [scheduler](exec.sched#concept:scheduler "33.6Schedulers[exec.sched]"),get_forward_progress_guarantee is ill-formed[.](#exec.get.fwd.progress-2.sentence-3)
Otherwise,get_forward_progress_guarantee(sch) is expression-equivalent to:
- [(2.1)](#exec.get.fwd.progress-2.1)
*MANDATE-NOTHROW*(*AS-CONST*(sch).query(get_forward_progress_guarantee)),
if that expression is well-formed[.](#exec.get.fwd.progress-2.1.sentence-1)
*Mandates*: The type of the expression above is forward_progress_guarantee[.](#exec.get.fwd.progress-2.1.sentence-2)
- [(2.2)](#exec.get.fwd.progress-2.2)
Otherwise, forward_progress_guarantee::weakly_parallel[.](#exec.get.fwd.progress-2.2.sentence-1)
[3](#exec.get.fwd.progress-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L1024)
If get_forward_progress_guarantee(sch) for some scheduler sch returns forward_progress_guarantee::concurrent,
all execution agents created by that scheduler's associated execution resource
shall provide the concurrent forward progress guarantee[.](#exec.get.fwd.progress-3.sentence-1)
If it returns forward_progress_guarantee::parallel,
all such execution agents
shall provide at least the parallel forward progress guarantee[.](#exec.get.fwd.progress-3.sentence-2)
### [33.5.9](#exec.get.compl.sched) execution::get_completion_scheduler [[exec.get.compl.sched]](exec.get.compl.sched)
[1](#exec.get.compl.sched-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L1035)
get_completion_scheduler<*completion-tag>* obtains
the completion scheduler associated with a completion tag
from a sender's attributes[.](#exec.get.compl.sched-1.sentence-1)
[2](#exec.get.compl.sched-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L1040)
The name get_completion_scheduler denotes a query object template[.](#exec.get.compl.sched-2.sentence-1)
For a subexpression q,
the expression get_completion_scheduler<*completion-tag*>(q) is ill-formed if *completion-tag* is not one ofset_value_t, set_error_t, or set_stopped_t[.](#exec.get.compl.sched-2.sentence-2)
Otherwise, get_completion_scheduler<*completion-tag*>(q) is expression-equivalent to*MANDATE-NOTHROW*(*AS-CONST*(q).query(get_completion_scheduler<*completion-tag*>))*Mandates*: If the expression above is well-formed,
its type satisfies [scheduler](exec.sched#concept:scheduler "33.6Schedulers[exec.sched]")[.](#exec.get.compl.sched-2.sentence-3)
[3](#exec.get.compl.sched-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L1055)
Let *completion-fn* be a completion function ([[exec.async.ops]](exec.async.ops "33.3Asynchronous operations"));
let *completion-tag* be
the associated completion tag of *completion-fn*;
let args be a pack of subexpressions; and
let sndr be a subexpression
such that [sender](exec.snd.concepts#concept:sender "33.9.3Sender concepts[exec.snd.concepts]")<decltype((sndr))> is true andget_completion_scheduler<*completion-tag*>(get_env(sndr)) is well-formed and denotes a scheduler sch[.](#exec.get.compl.sched-3.sentence-1)
If an asynchronous operation
created by connecting sndr with a receiver rcvr causes the evaluation of *completion-fn*(rcvr, args...),
the behavior is undefined
unless the evaluation happens on an execution agent
that belongs to sch's associated execution resource[.](#exec.get.compl.sched-3.sentence-2)
[4](#exec.get.compl.sched-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L1071)
The expressionforwarding_query(get_completion_scheduler<*completion-tag*>) is a core constant expression and has value true[.](#exec.get.compl.sched-4.sentence-1)
### [33.5.10](#exec.get.await.adapt) execution::get_await_completion_adaptor [[exec.get.await.adapt]](exec.get.await.adapt)
[1](#exec.get.await.adapt-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L1078)
get_await_completion_adaptor asks a queryable object for
its associated awaitable completion adaptor[.](#exec.get.await.adapt-1.sentence-1)
[2](#exec.get.await.adapt-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L1082)
The name get_await_completion_adaptor denotes a query object[.](#exec.get.await.adapt-2.sentence-1)
For a subexpression env,get_await_completion_adaptor(env) is expression-equivalent to*MANDATE-NOTHROW*(*AS-CONST*(env).query(get_await_completion_adaptor))
[3](#exec.get.await.adapt-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L1093)
forwarding_query(execution::get_await_completion_adaptor) is a core constant expression and has value true[.](#exec.get.await.adapt-3.sentence-1)