C++ Logo

std-proposals

Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Thu, 30 Nov 2023 09:43:45 -0500
On Thu, Nov 30, 2023 at 7:16 AM Bjorn Reese via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On 11/30/23 00:25, Frederick Virchanza Gotham via Std-Proposals wrote:
>
> > I think I'll just use this one-liner to abandon the value:
> >
> > ::new( &myvar.value() ) std::future<bool>();
>
> Why? Dragan has already explained that optional::reset() or reassignment
> handles the promise/future shared state correctly.

Because the entire point of the request is to *not* "handle the
promise/future shared state correctly". The point is to not call the
destructor, to skip proper cleanup and deliberately leak resources.

Received on 2023-11-30 14:44:04