Namespaces
Variants

Standard library header <coroutine> (C++20)

From cppreference.net
Standard library headers

このヘッダは 言語サポート ライブラリの一部です。

目次

インクルード

(C++20)
三方比較演算子 サポート

クラス

コルーチンプロミス型を検出するための特性型
(クラステンプレート)
中断または実行中のコルーチンを参照するために使用される
(クラステンプレート)
std::coroutine_handle のハッシュサポート
(クラステンプレートの特殊化)
No-opコルーチン
観測可能な効果を持たないコルーチンに使用される
(クラス)
std:: coroutine_handle < std:: noop_coroutine_promise > 、何もしないコルーチンを参照するためのもの
(typedef)
自明な Awaitables
待機式が中断されるべきではないことを示す
(クラス)
待機式が常に中断すべきであることを示す
(クラス)

関数

2つの coroutine_handle オブジェクトを比較する
(関数)
No-opコルーチン
再開または破棄されたときに観測可能な効果を持たないコルーチンハンドルを作成する
(関数)

概要

#include <compare>
namespace std {
  // コルーチン特性
  template<class R, class... ArgTypes>
    struct coroutine_traits;
  // コルーチンハンドル
  template<class Promise = void>
    struct coroutine_handle;
  // 比較演算子
  constexpr bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept;
  constexpr strong_ordering operator<=>(coroutine_handle<> x, 
                                        coroutine_handle<> y) noexcept;
  // ハッシュサポート
  template<class T> struct hash;
  template<class P> struct hash<coroutine_handle<P>>;
  // ノーオペレーションコルーチン
  struct noop_coroutine_promise;
  template<> struct coroutine_handle<noop_coroutine_promise>;
  using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
  noop_coroutine_handle noop_coroutine() noexcept;
  // 自明なアウェイタブル
  struct suspend_never;
  struct suspend_always;
}

クラステンプレート std::coroutine_handle

namespace std {
  template<>
  struct coroutine_handle<void>
  {
    // 構築/リセット
    constexpr coroutine_handle() noexcept;
    constexpr coroutine_handle(nullptr_t) noexcept;
    coroutine_handle& operator=(nullptr_t) noexcept;
    // エクスポート/インポート
    constexpr void* address() const noexcept;
    static constexpr coroutine_handle from_address(void* addr);
    // 観測
    constexpr explicit operator bool() const noexcept;
    bool done() const;
    // 再開
    void operator()() const;
    void resume() const;
    void destroy() const;
  private:
    void* ptr;  // 説明専用
  };
  template<class Promise>
  struct coroutine_handle
  {
    // 構築/リセット
    constexpr coroutine_handle() noexcept;
    constexpr coroutine_handle(nullptr_t) noexcept;
    static coroutine_handle from_promise(Promise&);
    coroutine_handle& operator=(nullptr_t) noexcept;
    // エクスポート/インポート
    constexpr void* address() const noexcept;
    static constexpr coroutine_handle from_address(void* addr);
    // 変換
    constexpr operator coroutine_handle<>() const noexcept;
    // 観測
    constexpr explicit operator bool() const noexcept;
    bool done() const;
    // 再開
    void operator()() const;
    void resume() const;
    void destroy() const;
    // promiseアクセス
    Promise& promise() const;
  private:
    void* ptr;  // 説明専用
  };
}

クラス std::noop_coroutine_promise

namespace std {
  struct noop_coroutine_promise {};
}

クラス std:: coroutine_handle < std:: noop_coroutine_promise >

namespace std {
  template<>
  struct coroutine_handle<noop_coroutine_promise>
  {
    // 変換
    constexpr operator coroutine_handle<>() const noexcept;
    // オブザーバー
    constexpr explicit operator bool() const noexcept;
    constexpr bool done() const noexcept;
    // 再開
    constexpr void operator()() const noexcept;
    constexpr void resume() const noexcept;
    constexpr void destroy() const noexcept;
    // promiseアクセス
    noop_coroutine_promise& promise() const noexcept;
    // アドレス
    constexpr void* address() const noexcept;
  private:
    coroutine_handle(/* 未指定 */);
    void* ptr; // 説明専用
  };
}

Class std::suspend_never

namespace std {
  struct suspend_never {
    constexpr bool await_ready() const noexcept { return true; }
    constexpr void await_suspend(coroutine_handle<>) const noexcept {}
    constexpr void await_resume() const noexcept {}
  };
}

クラス std::suspend_always

namespace std {
  struct suspend_always {
    constexpr bool await_ready() const noexcept { return false; }
    constexpr void await_suspend(coroutine_handle<>) const noexcept {}
    constexpr void await_resume() const noexcept {}
  };
}