Syntax sugar for {} with structs

IGotD- nise at nise.com
Fri Jul 1 18:54:24 UTC 2022


On Friday, 1 July 2022 at 11:51:57 UTC, ryuukk_ wrote:
> I had to write this recently
>
>
> ```D
>     void reset()
>     {
>         state.end_index = 0;
>         state.buffer_list = SinglyLinkedList!(ubyte[])();
>     }
> ```
>
> While not that bad, it's annoying, why can't we do like like:  
> `A a = {}`?
>
>
> ```D
>     void reset()
>     {
>         state.end_index = 0;
>         state.buffer_list = {};
>     }
> ```
>

Are you suggesting that D should copy the modern C++ uniform 
initialization? That's one thing I don't like with C++ because it 
is very ugly.

D also don't need it because D has default initialization as 
standard. C++ added the uniform initialization (among other 
things) in order to create a syntax where variables are properly 
initialized. D got this right from the beginning.

In D the .init property is usually fine for most cases.



More information about the Digitalmars-d mailing list