final_suspend() 并co_await 它的结果(例如,恢复某个继续或发布某个结果)。此时开始恢复协程是未定义行为。 当经由 co_return 或未捕获异常而终止协程导致协程状态被销毁,或通过它的句柄销毁它时,它进行下列操作: 调用承诺对象的析构函数。 调用各个函数形参副本的析构函数。 调用operator delete 以释放协程...
调用promise.initial_suspend()并co_await它的结果。典型的承诺类型Promise要么(对于惰性启动的协程)返回std::suspend_always,要么(对于急切启动的协程)返回std::suspend_never。 当co_await promise.initial_suspend()恢复时,开始协程体的执行。 一些形参会垂悬的例子: ...
std::suspend_never 自然相反constexpr bool await_ready() const noexcept { return true; } 所以对于initial_suspend 返回suspend_never 的即表示协程立刻启动,而 suspend_always 则表示后续 resume调用时才会启动。 而co_await switch_to_new_thread(out); 则调用了 switch_to_new_thread::awaitable::await_su...
co_awaitawait-expression(C++20) newnew[]Dynamic memory allocation deletedelete[]Dynamic memory deallocation 4.*->*Pointer-to-memberLeft-to-right → 5a*ba/ba%bMultiplication, division, and remainder 6a+ba-bAddition and subtraction 7<<>>Bitwiseleft shift and right shift ...
// assuming that task is some coroutine task typetask<void>f(){// not a coroutine, undefined behavior}task<void>g(){co_return;// OK}task<void>h(){co_await g();// OK, implicit co_return;} If the coroutine ends with an uncaught exception, it performs the following: ...
co_await co_return co_yield decltype default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new noexcept not not_eq nullptr operator or or_eq private protected public reflexpr register reinterpret_cast requires re...
co_await co_return co_yield decltype default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new noexcept not not_eq nullptr operator or or_eq private protected public reflexpr register reinterpret_cast requires return...
co_await(C++20) co_return(C++20) co_yield(C++20) decltype(C++11)(2) default(1) delete(1) do double dynamic_cast else enum(1) explicit export(1)(4) extern(1) false float for(1) friend goto if(3)(5) inline(1)(3) int(1) ...
C++ 关键词:co_await(C++20 起) C++ C++ 语言 if switch for while continue-break goto-return decltype auto constexpr consteval constinit --nullptr static_cast const_cast dynamic_cast reinterpret_cast explicit static 关键词 一元运算符co_await暂停协程并将控制权返回给调用者。
co_await (C++20) co_return (C++20) co_yield (C++20) decltype (C++11) (2) default (1) delete (1) do double dynamic_cast else enum (1) explicit export (1) (4) extern (1) false float for (1) friend goto if (3) (5) inline (1) (3) int (1) long mutable (1) namespace...