Date: Fri, 6 May 2022 07:11:09 +0200
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
> 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
Received on 2022-05-06 05:11:14