C++ Logo

std-proposals

Advanced search

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

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 28 Nov 2023 12:01:23 +0000
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.

Received on 2023-11-28 12:01:37