定制点是在制作框架时为了新增扩展在框架内所预留的接口,以协程为例 struct coroutine : std::coroutine_handle<promise> { using promise_type = ::promise; }; struct promise { coroutine get_return_object() { return {coroutine::from_promise(*this)}; } std::suspend_always initial_suspend() noexcept...
generator使用的promise_type继承自_Promise_erased和_Promise_alloc,简单添加了构造generator的成员函数。我们会着重考察_Erased_promise。 structpromise_type:_Erased_promise,__gen::_Promise_alloc<_Alloc>{generatorget_return_object()noexcept{return{coroutine_handle<promise_type>::from_promise(*this)};}}; ...
- 调用这个std::coroutine_handle<> -销毁这个协程函数 代码语言:javascript 代码运行次数:0 运行 AI代码解释 #include <concepts> #include <coroutine> #include <exception> #include <iostream> struct ReturnObject { struct promise_type { ReturnObject get_return_object() { return {}; } std::suspend_...
它分为模板 std::coroutine_handle<Promise> 和模板特化 std::coroutine_handle<void> , std::coroutine_handle<void> 可以简单理解为就是做了类型擦除的 std::coroutine_handle<Promise> 。 打开<coroutine> 头文件我们不难看出, std::coroutine_handle<Promise> 中的不少方法是依靠 __builtin 内建函数,也就...
类模板coroutine_handle能用于指代暂停或执行的协程。coroutine_handle的每个特化均为字面类型(LiteralType)。 1)主模板,可从Promise类型的承诺对象创建。 2)特化std::coroutine_handle<void>是其他特化的公开基类。它保有协程柄的底层地址。 3)特化std::coroutine_handle<std::noop_coroutine_promise>指代无操作协程。
类模板 coroutine_handle 能用于指代暂停或执行的协程。 coroutine_handle 的每个特化均为字面类型 (LiteralType) 。1) 主模板,可从 Promise 类型的承诺对象创建。 2) 特化 std::coroutine_handle<void> 擦除承诺类型。它可从其他特化转换。 3) 特化 std::coroutine_handle<std::noop_coroutine_promise> 指代无...
只要有某个 std::noop_coroutine_handle 指代无操作协程,该协程的承诺对象就不会被销毁。 std::coroutine_handle<Promise> 可能指代协程类型异于 Promise 的协程,若它由 from_address 创建,或其 std::coroutine_handle<> 基类子对象被从 std::coroutine_handle<AnotherPromise> 的基类子对象赋值。
特化std::coroutine_handle<std::noop_coroutine_promise> 的成员 constexpr bool done() const noexcept; (2) (C++20 起) 检查暂停的协程是否在其最终暂停点暂停。1) 若 *this 所指代的协程在其最终暂停点暂停则返回 true ,若该协程在其他暂停点暂停则返回 false 。若 *this 不指代暂停的协程则行为未定义...
1)Primary template, can be created from the promise object of typePromise. 2)Specializationstd::coroutine_handle<void>erases the promise type. It is convertible from other specializations. 3)Specializationstd::coroutine_handle<std::noop_coroutine_promise>refers to no-op coroutines. It cannot be ...
This conversion function converts a std::coroutine_handle<Promise> value to a std::coroutine_handle<> holding the same underlying address. It effectively erases the promise type. Parameters (none) Return value std::coroutine_handle<>::from_address(address()). See also operator==operator<=...