C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Replace an object -- but retain old object if new object fails to construct

From: organicoman <organicoman_at_[hidden]>
Date: Fri, 24 Oct 2025 17:13:11 +0100
Hi,You have introduced a new concept. Object lifetime suspension. But that's not how you defend it.Let me ask you a couple of questions and try to answer them.- what are the pre-conditions on a type so it can suspended its lifetime ?- the post conditions?- can it be implemented with -fno-exception?- how it is handled in a multi-threaded environment?- does it provide any speed advantage over current operations (copy, move)?- what patterns resembles to it, or leads to it?And so forth.Sent from my Galaxy
-------- Original message --------From: Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Date: 10/24/25 4:24 PM (GMT+01:00) To: std-proposals_at_[hidden] Cc: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]> Subject: Re: [std-proposals] Replace an object -- but retain old object if new object fails to construct On Friday, October 24, 2025, Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]> wrote:
I think that's an even more important question: how often do we need this
replacement solution whereby the previously-stored object is present if the
new one throws on construction?
Sometimes we at the very least want to be left with a safe-to-destroy object if the construction fails. Something like: p->~T(); try { ::new(p) T(5, 6.22); } catch(...) { std::construct_moved_from_at<T>(p); }A few months back on this mailing list, somebody was talking about introducing "std::moved_from" and I think it's a good idea.

Received on 2025-10-24 16:13:23