æ ååºæ 头 <coroutine>
æ¥èªcppreference.com
æ¤å¤´æä»¶æ¯åç¨æ¯æåºçä¸é¨åã
å å« | ||
(C++20) |
ä¸è·¯æ¯è¾è¿ç®ç¬¦æ¯æ | |
ç±» | ||
(C++20) |
ç¨äºåç°åç¨æ¿è¯ºç±»åçç¹å¾ç±»å (类模æ¿) | |
(C++20) |
ç¨äºæä»£æåææ§è¡çåç¨ (类模æ¿) | |
std::coroutine_handle çæ£åæ¯æ (类模æ¿ç¹å) | ||
æ æä½åç¨ | ||
(C++20) |
ç¨äºæ å¯è§å¯ä½ç¨çåç¨ (ç±») | |
(C++20) |
std::coroutine_handle<std::noop_coroutine_promise> ï¼ææç¨äºæä»£æ æä½åç¨ (typedef) | |
å¹³å¡å¯çå¾ ä½ | ||
(C++20) |
æç¤º await 表达å¼åºè¯¥å³ä¸æå (ç±») | |
(C++20) |
æç¤º await 表达å¼åºè¯¥å§ç»æå (ç±») | |
彿° | ||
(C++20) |
æ¯è¾äºä¸ª coroutine_handle 对象 (彿°) | |
æ æä½åç¨ | ||
(C++20) |
å建å¨çå¾
æéæ¯æ¶æ å¯è§å¯ä½ç¨çåç¨æ (彿°) |
[ç¼è¾] æ¦è¦
#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() 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; // æ¿è¯ºè®¿é® noop_coroutine_promise& promise() const noexcept; // å°å constexpr void* address() const noexcept; private: coroutine_handle(/* æªææ */); void* ptr; // ä» ç¨äºéé }; }
[ç¼è¾] ç±» 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 {} }; }