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: Mon, 27 Oct 2025 11:46:19 +0000
On Mon, Oct 27, 2025 at 11:41 AM Frederick Virchanza Gotham wrote:
>
> If you really want to assign to a moved_from object, I think just do:
>
> Func( std::move(var) );
> ::new( &var ) T( SomeOtherFunc() );


Sorry I should clarify that I meant this in a parallel universe where
all moved_from objects have a no-op destruction . . . but then of
course we could still have a problem here if the constructor throws.

Never mind.

Received on 2025-10-27 11:45:53