On Friday, 28 November 2025 at 18:42:44 UTC, drug007 wrote:
On 28.11.2025 21:14, tzsz wrote:
In C++ it is called placement new. In D you should emplace class:


This is quite helpful. Could you provide another toy example where we have abstract Vehicle class, then effective Car class derived from Vehicle, then Toyota class derived from Car class. The Toyota class needs to call Car constructor, which may need to call Vehicle constructor, then complete its own constructor. Vehicle class has member of int speed (in Miles per hour), which will be used in the example. All classes have explicit constructors and explicit destructors.

This example would complete the understanding of using emplace for me.
Working examples that can be reproduced are the best teachers.

It is my understanding that using emplace as shown will make this class pointer outside the scope of the GC.

Avoiding GC seems to be popular with Zig, Rust and other languages.
It seems that D can play this game too.

Reply via email to