Standard library header <coroutine> (哋它亢++20)

From cppreference.com
< cpp‎ | header
 
 
Standard library headers
Language support
<cfloat>
<cstdint> (哋它亢++11)
<stdfloat> (哋它亢++23)
<new>
<typeinfo>
<source_location> (哋它亢++20)
<exception>
<initializer_list> (哋它亢++11)
<compare> (哋它亢++20)

<coroutine> (哋它亢++20)
<csignal>
<csetjmp>
<cstdarg>

Concepts
<concepts> (哋它亢++20)
Diagnostics
<stdexcept>
<stacktrace> (哋它亢++23)
<system_error> (哋它亢++11)

Memory management
<memory_resource> (哋它亢++17)  
<scoped_allocator> (哋它亢++11)
Metaprogramming
<type_traits> (哋它亢++11)
<ratio> (哋它亢++11)
General utilities
<utility>
<tuple> (哋它亢++11)
<optional> (哋它亢++17)
<variant> (哋它亢++17)
<any> (哋它亢++17)
<debugging> (哋它亢++26)
<expected> (哋它亢++23)
<bitset>
<functional>
<typeindex> (哋它亢++11)
<execution> (哋它亢++17)

<charconv> (哋它亢++17)
<format> (哋它亢++20)
<bit> (哋它亢++20)

Strings
<string_view> (哋它亢++17)
<string>
<cuchar> (哋它亢++11)

Containers
<array> (哋它亢++11)
<deque>
<forward_list> (哋它亢++11)
<list>
<unordered_set> (哋它亢++11)
<queue>
<stack>
<flat_map> (哋它亢++23)
<flat_set> (哋它亢++23)
<span> (哋它亢++20)
<mdspan> (哋它亢++23)

Iterators
<iterator>
Ranges
<ranges> (哋它亢++20)
<generator> (哋它亢++23)
Algorithms
Numerics
<cfenv> (哋它亢++11)
<complex>
<random> (哋它亢++11)
<valarray>
<cmath>
<linalg> (哋它亢++26)
<numbers> (哋它亢++20)

Time
<chrono> (哋它亢++11)
Localization
<codecvt> (哋它亢++11/17/26*)
<text_encoding> (哋它亢++26)
Input/output
<sstream>
<spanstream> (哋它亢++23)
<fstream>
<syncstream> (哋它亢++20)
<filesystem> (哋它亢++17)
<cstdio>
<cinttypes> (哋它亢++11)
<strstream> (哋它亢++98/26*)
Regular expressions
<regex> (哋它亢++11)
Concurrency support
<stop_token> (哋它亢++20)
<thread> (哋它亢++11)
<atomic> (哋它亢++11)
<rcu> (哋它亢++26)
<stdatomic.h> (哋它亢++23)
<mutex> (哋它亢++11)
<shared_mutex> (哋它亢++14)

<condition_variable> (哋它亢++11)  
<semaphore> (哋它亢++20)
<latch> (哋它亢++20)

<barrier> (哋它亢++20)
<future> (哋它亢++11)
<hazard_pointer> (哋它亢++26)

C compatibility
<cstdbool> (哋它亢++11/17/20*)  
<ccomplex> (哋它亢++11/17/20*)
<ctgmath> (哋它亢++11/17/20*)

<cstdalign> (哋它亢++11/17/20*)

<ciso646> (until 哋它亢++20)

 

This header is part of the coroutine support library.

Includes

(哋它亢++20)
Three-way comparison operator support

Classes

(哋它亢++20)
trait type for discovering coroutine promise types
(class template)
(哋它亢++20)
used to refer to a suspended or executing coroutine
(class template)
hash support for std::coroutine_handle
(class template specialization)
No-op Coroutines
used for coroutines with no observable effects
(class)
(哋它亢++20)
std::coroutine_handle<std::noop_coroutine_promise>, intended to refer to a no-op coroutine
(typedef)
Trivial Awaitables
(哋它亢++20)
indicates that an await-expression should never suspend
(class)
(哋它亢++20)
indicates that an await-expression should always suspend
(class)

Functions

(哋它亢++20)
compares two coroutine_handle objects
(function)
No-op Coroutines
(哋它亢++20)
creates a coroutine handle that has no observable effects when resumed or destroyed
(function)

Synopsis

#include <compare>
 
namespace std {
  // coroutine traits
  template<class R, class... ArgTypes>
    struct coroutine_traits;
 
  // coroutine handle
  template<class Promise = void>
    struct coroutine_handle;
 
  // comparison operators
  constexpr bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept;
  constexpr strong_ordering operator<=>(coroutine_handle<> x, 
                                        coroutine_handle<> y) noexcept;
 
  // hash support
  template<class T> struct hash;
  template<class P> struct hash<coroutine_handle<P>>;
 
  // no-op coroutines
  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;
 
  // trivial awaitables
  struct suspend_never;
  struct suspend_always;
}

Class template std::coroutine_handle

namespace std {
  template<>
  struct coroutine_handle<void>
  {
    // construct/reset
    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);
 
    // observers
    constexpr explicit operator bool() const noexcept;
    bool done() const;
 
    // resumption
    void operator()() const;
    void resume() const;
    void destroy() const;
 
  private:
    void* ptr;  // exposition only
  };
 
  template<class Promise>
  struct coroutine_handle
  {
    // construct/reset
    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);
 
    // conversion
    constexpr operator coroutine_handle<>() const noexcept;
 
    // observers
    constexpr explicit operator bool() const noexcept;
    bool done() const;
 
    // resumption
    void operator()() const;
    void resume() const;
    void destroy() const;
 
    // promise access
    Promise& promise() const;
 
  private:
    void* ptr;  // exposition only 
  };
}

Class std::noop_coroutine_promise

namespace std {
  struct noop_coroutine_promise {};
}

Class std::coroutine_handle<std::noop_coroutine_promise>

namespace std {
  template<>
  struct coroutine_handle<noop_coroutine_promise>
  {
    // conversion
    constexpr operator coroutine_handle<>() const noexcept;
 
    // observers
    constexpr explicit operator bool() const noexcept;
    constexpr bool done() const noexcept;
 
    // resumption
    constexpr void operator()() const noexcept;
    constexpr void resume() const noexcept;
    constexpr void destroy() const noexcept;
 
    // promise access
    noop_coroutine_promise& promise() const noexcept;
 
    // address
    constexpr void* address() const noexcept;
  private:
    coroutine_handle(/* unspecified */);
    void* ptr; // exposition only 
  };
}

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

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