Namespaces
Variants

std::execution:: then

From cppreference.net
定义于头文件 <execution>
execution :: sender auto then ( execution :: sender auto input,
std:: invocable < /*values-sent-by*/ ( input ) ... > function ) ;
(C++26 起)

参数

input - 发送方,执行后传递函数运行所需的参数值
function - 可调用对象,将由链接到输入发送方的新发送方调用

返回值

返回一个描述输入发送方所描述任务图的发送方,其中新增了一个节点,该节点会调用提供的函数,并将输入发送方发送的值作为参数。

then 保证在返回的 sender 启动之前不会开始执行函数。

示例

可能的 execution::then 用法。

execution::sender auto input = get_input();
execution::sender auto snd = execution::then(input, [](auto... args)
{
    std::print(args...);
});
// snd 描述了由 pred 定义的工作
// 后接打印 pred 发送的所有值