Syntax sugar for {} with structs

ryuukk_ ryuukk.dev at gmail.com
Fri Jul 1 11:51:57 UTC 2022


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 = {};
     }
```

It is much easier to read, i do not use constructors or RAII, and 
i feel like i'm being penalized because i want to keep things 
simple


Could it be allowed for cases where there are no constructors? i 
don't know the rules about them, but if one is automatically 
generated, maybe check for `@disable`d

Maybe it could be a syntax sugar for `state.buffer_list = 
state.buffer_list.init`

Even though i also hate `.init` because just like `destroy` they 
are already used in druntime and therefore i can't use them 
myself.. i hate rules like that


Quality of life for people who only live with structs, please!


More information about the Digitalmars-d mailing list