C++ Logo

std-proposals

Advanced search

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

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Mon, 27 Oct 2025 12:31:35 +0100
We have relocation for this.   -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> 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_at_[hidden]; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; 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_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-10-27 11:44:44