Namespaces
Variants

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

From cppreference.net
Standard library headers

Dieser Header ist Teil der Sprachunterstützungsbibliothek .

Inhaltsverzeichnis

Includes

(C++20)
Unterstützung für den Drei-Wege-Vergleichsoperator

Klassen

Merkmalstyp zur Ermittlung von Coroutine-Promise-Typen
(Klassentemplate)
wird verwendet, um sich auf eine angehaltene oder ausgeführte Coroutine zu beziehen
(Klassentemplate)
Hash-Unterstützung für std::coroutine_handle
(Klassen-Templatespezialisierung)
No-op Coroutinen
wird für Coroutinen ohne beobachtbare Effekte verwendet
(Klasse)
std:: coroutine_handle < std:: noop_coroutine_promise > , dient zur Referenzierung einer No-Op-Coroutine
(Typdefinition)
Trivial Awaitables
gibt an, dass ein Await-Ausdruck niemals suspendieren sollte
(Klasse)
gibt an, dass ein Await-Ausdruck immer suspendieren sollte
(Klasse)

Funktionen

vergleicht zwei coroutine_handle Objekte
(Funktion)
No-op Coroutinen
erstellt ein Coroutine-Handle, das bei Wiederaufnahme oder Zerstörung keine beobachtbaren Effekte hat
(Funktion)

Übersicht

#include <compare>
namespace std {
  // Coroutinen-Traits
  template<class R, class... ArgTypes>
    struct coroutine_traits;
  // Coroutinen-Handle
  template<class Promise = void>
    struct coroutine_handle;
  // Vergleichsoperatoren
  constexpr bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept;
  constexpr strong_ordering operator<=>(coroutine_handle<> x, 
                                        coroutine_handle<> y) noexcept;
  // Hash-Unterstützung
  template<class T> struct hash;
  template<class P> struct hash<coroutine_handle<P>>;
  // No-Op-Coroutinen
  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;
  // Triviale Awaitables
  struct suspend_never;
  struct suspend_always;
}

Klassentemplate std::coroutine_handle

namespace std {
  template<>
  struct coroutine_handle<void>
  {
    // Konstruktion/Zurücksetzen
    constexpr coroutine_handle() noexcept;
    constexpr coroutine_handle(nullptr_t) noexcept;
    coroutine_handle& operator=(nullptr_t) noexcept;
    // Export/Import
    constexpr void* address() const noexcept;
    static constexpr coroutine_handle from_address(void* addr);
    // Beobachter
    constexpr explicit operator bool() const noexcept;
    bool done() const;
    // Fortsetzung
    void operator()() const;
    void resume() const;
    void destroy() const;
  private:
    void* ptr;  // nur zur Darstellung
  };
  template<class Promise>
  struct coroutine_handle
  {
    // Konstruktion/Zurücksetzen
    constexpr coroutine_handle() noexcept;
    constexpr coroutine_handle(nullptr_t) noexcept;
    static coroutine_handle from_promise(Promise&);
    coroutine_handle& operator=(nullptr_t) noexcept;
    // Export/Import
    constexpr void* address() const noexcept;
    static constexpr coroutine_handle from_address(void* addr);
    // Konvertierung
    constexpr operator coroutine_handle<>() const noexcept;
    // Beobachter
    constexpr explicit operator bool() const noexcept;
    bool done() const;
    // Fortsetzung
    void operator()() const;
    void resume() const;
    void destroy() const;
    // Promise-Zugriff
    Promise& promise() const;
  private:
    void* ptr;  // nur zur Darstellung
  };
}

Klasse std::noop_coroutine_promise

namespace std {
  struct noop_coroutine_promise {};
}

Klasse std:: coroutine_handle < std:: noop_coroutine_promise >

namespace std {
  template<>
  struct coroutine_handle<noop_coroutine_promise>
  {
    // Konvertierung
    constexpr operator coroutine_handle<>() const noexcept;
    // Beobachter
    constexpr explicit operator bool() const noexcept;
    constexpr bool done() const noexcept;
    // Fortsetzung
    constexpr void operator()() const noexcept;
    constexpr void resume() const noexcept;
    constexpr void destroy() const noexcept;
    // Promise-Zugriff
    noop_coroutine_promise& promise() const noexcept;
    // Adresse
    constexpr void* address() const noexcept;
  private:
    coroutine_handle(/* unspecified */);
    void* ptr; // nur zur Darstellung
  };
}

Klasse 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 {}
  };
}

Klasse 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 {}
  };
}