C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return value lives until end of scope

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sat, 23 May 2026 08:23:16 +0000
On Saturday, May 23, 2026, Sebastian Wittmeier wrote:

>
> You can use a single variable (container for futures) and use it as
> reference parameter to a function creating your async call.
>


I think the following:

int main()
{

for ( unsigned i = 0u; i < N; ++i )
{
    %%async(Func);
}

}

would have to be implemented by the compiler something like:

int main()
{

struct Frame {
    alignas(std::future<int>) char unsigned f[ sizeof(std::future<int>) ];
    Frame *next;
};

Frame fr;
Frame *p = &fr;

for ( unsigned i = 0u; i < N; ++i )
{
    ::new(p->f) std::future<int>{ async(Func) };
    p->next = alloca( sizeof *p );
    p->next.next = nullptr;
    p = p->next;
}

for ( p = &fr; nullptr != p; p = p->next )
{
    ((std::future<int>*)p->f)->~std::future<int>();
}

Received on 2026-05-23 08:23:20