C++ Logo


Advanced search

Coroutine local destructor

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Fri, 22 May 2020 18:55:20 +0200
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.

Received on 2020-05-22 11:58:35