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@lists.isocpp.org>
Date: 5/6/22 9:11 AM (GMT+04:00)
To: std-proposals@lists.isocpp.org, Ville Voutilainen <ville.voutilainen@gmail.com>
Cc: Jens Maurer <Jens.Maurer@gmx.net>, S├ębastien Bini <sebastien.bini@gmail.com>
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 {

void f() {
  A a(5);           // #1
  new (&a) A(6);    // ends lifetime of object created at #1 by re-using its storage

Std-Proposals mailing list