Namespaces
Variants

std::execution:: read_env

From cppreference.net
定义于头文件 <execution>
inline constexpr /*unspecified*/ read_env { } ;
(C++26 起)
(定制点对象)
调用签名
execution :: sender auto read_env ( auto && query ) ;
(C++26 起)

一个发送器工厂,返回的发送器能够访问接收器的环境并提取与给定 查询对象 关联的当前值。

对于任何查询对象 q ,表达式 read_env ( q ) /*make-sender*/ ( read_env, q ) 具有 表达式等价性

定制点对象

名称 execution::read_env 表示一个 定制点对象 ,它是一个字面量 semiregular 类类型的常量 函数对象 。详情参见 定制点对象

示例

该工厂的一个使用示例是在接收器的调度器上安排依赖工作,可通过 read_env ( get_scheduler ) 获取该调度器:

std::execution::sender auto task =
  std::execution::read_env(std::execution::get_scheduler)
    | std::execution::let_value([](auto sched) {
        return std::execution::starts_on(sched, /*此处为嵌套工作内容*/);
    });
std::this_thread::sync_wait( std::move(task) ); // 等待其执行完成