std::execution::read_env

来自cppreference.com
< cpp‎ | execution
 
 
 
在标头 <execution> 定义
inline constexpr /* 未指明 */ 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 类类型的 const 函数对象。 细节参见定制点对象 (CustomizationPointObject)

[编辑] 示例

这个工厂的一个用法示例,是在接收器的调度器上调度待决的工作,可以通过 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) ); // 等待它完成