最終更新日時(UTC):
が更新

履歴 編集

customization point object
<execution>

std::execution::upon_stopped(C++26)

namespace std::execution {
  struct upon_stopped_t { unspecified };
  inline constexpr upon_stopped_t upon_stopped{};
}

概要

upon_stoppedは、入力Sender停止完了操作の継続として関数呼び出しをアタッチし、戻り値データを正常完了として送信するSenderアダプタである。

upon_stoppedパイプ可能Senderアダプタオブジェクトであり、パイプライン記法をサポートする。

Senderアルゴリズムupon_stoppedの仕様は、thenページを参照のこと。

#include <print>
#include <execution>
namespace ex = std::execution;

int main()
{
  { // 関数呼び出し
    ex::sender auto snd0 = ex::just_stopped();
    ex::sender auto snd1 = ex::upon_stopped(snd0, []() {
      return 42;
    });
    auto [v] = std::this_thread::sync_wait(snd1).value();
    std::println("{}", v);
  }

  { // パイプライン記法
    ex::sender auto sndr = ex::just_stopped()
      | ex::upon_stopped([]() {
          return 42;
        });
    auto [v] = std::this_thread::sync_wait(sndr).value();
    std::println("{}", v);
  }
}

出力

42
42

バージョン

言語

  • C++26

処理系

関連項目

参照