C++ Logo

std-proposals

Advanced search

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

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Fri, 24 Oct 2025 15:24:21 +0000
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 15:24:23