C++ Logo

std-proposals

Advanced search

Re: [std-proposals] void std::optional<T>::abandon(void) noexcept

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Tue, 28 Nov 2023 16:15:55 +0300
On 11/28/23 15:01, Frederick Virchanza Gotham via Std-Proposals wrote:
> Let's say I have a variable defined as follows:
>
> optional< future<bool> > var;
>
> And let's say I assign the return value of an invocation of 'async' to
> it. Later I wait on the future object for 3 seconds, and it's not
> ready after 3 seconds so I assume my thread is frozen and so I give up
> on it.
>
> I want to reuse my 'var' variable, but I don't want to call the
> destructor of the future object. In this circumstance, it would be
> nice to be able to do:
>
> var.abandon();
>
> The member function "abandon" would set the 'var' object to having no
> value -- but it doesn't call the destructor of T.

This would result in UB or resource leak. No, thanks.

Received on 2023-11-28 13:15:58