Date: Sun, 25 Dec 2022 21:40:21 -0500
`coroutine_handle<T>::from_promise(T &p)` requires that "`p` is a
reference to a promise object of a coroutine."
OK, but... a reference to a base class subobject is also a reference
to the most derived-object, right? So if you have some type `T` which
you use as a coroutine's promise, you can in theory manufacture a
`coroutine_handle<U>` for that object if `U` is a base class subobject
of `T`:
```
struct T : public U
{
coroutine_handle<U> make_base_handle()
{
return coroutine_handle<U>::from_promise(*this);
}
}
```
So long as `*this` is a `T` which is a promise object, this ought to
work. But I'm pretty sure it *shouldn't*.
`from_promise(p)` should additionally require that `p` refers to the
most-derived object. IE: not a base class of a promise object.
reference to a promise object of a coroutine."
OK, but... a reference to a base class subobject is also a reference
to the most derived-object, right? So if you have some type `T` which
you use as a coroutine's promise, you can in theory manufacture a
`coroutine_handle<U>` for that object if `U` is a base class subobject
of `T`:
```
struct T : public U
{
coroutine_handle<U> make_base_handle()
{
return coroutine_handle<U>::from_promise(*this);
}
}
```
So long as `*this` is a `T` which is a promise object, this ought to
work. But I'm pretty sure it *shouldn't*.
`from_promise(p)` should additionally require that `p` refers to the
most-derived object. IE: not a base class of a promise object.
Received on 2022-12-26 02:42:51