We have relocation for this.
-----Ursprüngliche Nachricht-----
Von: Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mo 27.10.2025 12:41
Betreff: Re: [std-proposals] Replace an object -- but retain old object if new object fails to construct
An: std-proposals@lists.isocpp.org;
CC: Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>;
On Mon, Oct 27, 2025 at 11:05 AM Sebastian Wittmeier wrote:
>
> - Not all class objects have a moved-from state
This can be determined from std::is_move_constructible_v.
> - Some objects need tidying up even in their moved-from state,
> e.g. freeing memory from the heap
I think C++11 was too liberal with what a 'moved-from' object can do .
. . I would have limited it to "safe to destroy". I would _not_ have
made it safe to assign, nor safe to invoke methods on.
If you really want to assign to a moved_from object, I think just do:
Func( std::move(var) );
::new( &var ) T( SomeOtherFunc() );
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals