C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Class Instance Re-Use/Re-Init

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 14 Aug 2022 14:15:10 -0400
On Sun, Aug 14, 2022 at 12:54 PM Greg McPherran via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> I propose a ctor-like re-use/re-init special function that supports re-use of objects without any memory operations (new/delete). An analogy that I use is the reset() function of unique_ptr. However, my suggestion goes beyond that such that this re-use capability is a ctor-like once-and-done special function that is not available as a normal function - just as the ctor is not available as a normal function once the instance has been created.

Why does this need to be a special capability of the language/library?
Why do you want to impose a specific API on all (or at least many)
types? What exactly is the use case for this? You're talking about a
circumstance where: A) you want to reset a type, B) delete&placement
`new` would be inappropriate for some reason, and C) you don't have
control over the type itself to just give it a member function that
does this.

Is this common enough to need such a change? Equally importantly...
can't you just use `std::optional` to give that power to *any* type?

Received on 2022-08-14 18:15:35