C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Relocation in C++

From: organicoman <organicoman_at_[hidden]>
Date: Fri, 06 May 2022 11:38:55 +0400
What about non trivial struct, which free resources by calling its destructor?Sent from my Galaxy
-------- Original message --------From: Jens Maurer via Std-Proposals <std-proposals_at_[hidden]> Date: 5/6/22 9:11 AM (GMT+04:00) To: std-proposals_at_[hidden], Ville Voutilainen <ville.voutilainen_at_[hidden]> Cc: Jens Maurer <Jens.Maurer_at_[hidden]>, S├ębastien Bini <sebastien.bini_at_[hidden]> Subject: Re: [std-proposals] Relocation in C++ On 05/05/2022 23.10, Arthur O'Dwyer via Std-Proposals wrote:> If you mean that today there's a way to end the lifetime of a /non/-trivially-destructible object without calling its destructor (and without just ending the execution of the whole C++ program), then I didn't know about that. What is that way?Just re-use its memory for a different object:#include <new>struct A { A(int); ~A();};void f() { A a(5); // #1 new (&a) A(6); // ends lifetime of object created at #1 by re-using its storage}Jens-- Std-Proposals mailing listStd-Proposals_at_[hidden]://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-05-06 07:39:03