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

81 lines
3.8 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.env]
# 33 Execution control library [[exec]](./#exec)
## 33.11 Queryable utilities [[exec.envs]](exec.envs#exec.env)
### 33.11.2 Class template env [exec.env]
namespace std::execution {template<[*queryable*](exec.queryable.concept#concept:queryable "33.2.2queryable concept[exec.queryable.concept]")... Envs>struct [env](#lib:env "33.11.2Class template env[exec.env]") { Envs0 envs0; // *exposition only* Envs1 envs1; // *exposition only*
Envsn−1 envsn−1; // *exposition only*template<class QueryTag>constexpr decltype(auto) query(QueryTag q) const noexcept(*see below*); }; template<class... Envs> env(Envs...) -> env<unwrap_reference_t<Envs>...>;}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6246)
The class template env is used to construct a queryable object
from several queryable objects[.](#1.sentence-1)
Query invocations on the resulting object are resolved
by attempting to query each subobject in lexical order[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6252)
Specializations of env are not assignable[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6255)
It is unspecified
whether env supports initialization
using a parenthesized [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1General[expr.post.general]") ([[dcl.init]](dcl.init "9.5Initializers")),
unless the [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1General[expr.post.general]") consist of
a single element of type (possibly const) env[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6262)
[*Example [1](#example-1)*: template<[sender](exec.snd.concepts#concept:sender "33.9.3Sender concepts[exec.snd.concepts]") Sndr> sender auto parameterize_work(Sndr sndr) {// Make an environment such that:// get_allocator(env) returns a reference to a copy of my_alloc{}// get_scheduler(env) returns a reference to a copy of my_sched{}auto e = env{prop(get_allocator, my_alloc{}),
prop(get_scheduler, my_sched{})}; // Parameterize the input sender so that it will use our custom execution environment.return write_env(sndr, e);} — *end example*]
[🔗](#lib:query,env)
`template<class QueryTag>
constexpr decltype(auto) query(QueryTag q) const noexcept(see below);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6286)
Let [*has-query*](#concept:has-query "33.11.2Class template env[exec.env]") be the following exposition-only concept:template<class Env, class QueryTag>concept [*has-query*](#concept:has-query "33.11.2Class template env[exec.env]") = // *exposition only*requires (const Env& env) { env.query(QueryTag()); };
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6296)
Let *fe* be the first element ofenvs0, envs1, …, envsn−1 such that the expression *fe*.query(q) is well-formed[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6301)
*Constraints*: ([*has-query*](#concept:has-query "33.11.2Class template env[exec.env]")<Envs, QueryTag> || ...) is true[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6305)
*Effects*: Equivalent to: return *fe*.query(q);
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6309)
*Remarks*: The expression in the noexcept clause is equivalent
to noexcept(*fe*.query(q))[.](#9.sentence-1)