First Draft: Placement New Expression

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Sat Nov 2 06:01:24 UTC 2024


On 02/11/2024 6:47 PM, Richard (Rikki) Andrew Cattermole wrote:
> After thinking about this a bit, this expression is going to have to be 
> ``@system``.
> 
> Unfortunately this compiles:
> 
> ```d
> cast(void[])new int[1];
> ```
> 
> And so would this, without calling the destructor:
> 
> ```d
> T* t = new T(...);
> new(t)T(...)
> ```

Given this, I have to ask the question, what is the purpose of adding 
this expression to the language if it cannot be ``@safe``?

For ``@system`` tasks like initialization it should be expected to have 
to import and call functions to do that action, as it should not occur 
in normal code.

Would it not be better to do a bit of design work on ``emplace`` instead 
to improve its usability so that it consistently has this form:

```d
size_t calculateSizeOf(T)();
size_t calculateSizeOf(T)(size_t count);
T emplace(T)(void[]);
```



More information about the dip.development mailing list