C++ Logo

std-proposals

Advanced search

Re: Coroutine local destructor

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Fri, 22 May 2020 13:09:24 -0400
Could you post a complete compilable example, something with a clear metric
for "works as intended"? I can't follow these one-line snippets at all.

–Arthur

On Fri, May 22, 2020 at 12:55 PM Marcin Jaczewski via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> After some time playing around C++20 I find out that corutine can't
> have local aware destructor.
>
> code like this:
> ```
> task<> foo(Storage& t, Args args);
> ```
>
> Can use operator `new` like:
> ```
> void* operator new(std::size_t s, Storage& t, Args args);
> ```
>
> But destructor can only have two forms:
> ```
> void operator delete(void* p, std::size_t s);
> void operator delete(void* p);
> ```
>
> This mean if I would want store this corutine in `Storage` then I have
> now easy way to inform `Storage` to release memory for that corutine.
>
> Could be possible for C++ support destructor like:
> ```
> void operator delete(void* p, std::size_t s, Storage& t, Args args);
> ```
>
> or at least new in C++20 destructor:
> ```
> void operator delete(task_promise* p, std::destroying_delete_t);
> ```
>
> second options will have benefit of not needed defining how exactly
> args could survive to point of calling destructor as they should be
> placed on allocated space by corutine.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2020-05-22 12:12:40