Syntax sugar for {} with structs

ryuukk_ ryuukk.dev at gmail.com
Fri Jul 1 17:39:26 UTC 2022


On Friday, 1 July 2022 at 17:33:55 UTC, ryuukk_ wrote:
> On Friday, 1 July 2022 at 15:55:50 UTC, Paul Backus wrote:
>> On Friday, 1 July 2022 at 11:51:57 UTC, ryuukk_ wrote:
>>> Maybe it could be a syntax sugar for `state.buffer_list = 
>>> state.buffer_list.init`
>>
>> Simple enough to write a utility function that does this:
>>
>> ```d
>> void reset(T)(ref T obj)
>> {
>>     obj = typeof(obj).init;
>> }
>> ```
>>
>> Now you can write `reset(state.buffer_list)` (or 
>> `state.buffer_list.reset` if you prefer). No need to repeat 
>> yourself.
>
> We have to stop with utility function to solve annoyances like 
> this
>
> I'd use an other language if i have to keep writing utility 
> functions and templates all over the place and keep importing 
> ton of modules because the language refuses to evolve paste the 
> 80's

     A a;
     a = new();


Even C# added that recently: 
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/target-typed-new




More information about the Digitalmars-d mailing list