Syntax sugar for {} with structs

Salih Dincer salihdb at hotmail.com
Sat Jul 2 03:59:53 UTC 2022


On Friday, 1 July 2022 at 11:51:57 UTC, ryuukk_ wrote:
> ```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

I also like simple things. But I don't think it should be that 
simple!


>
> Why it's not a confusion here?, we don't do things like this:
> ```d
>    stuff(byte(1), int(1215145415));
> ```d
>

It already supports something like this:
```d
struct POW(byte n)
{
   int result;

   this(int pow)
   {
     print(int(pow), byte(n));
   }

   void print(int pow, byte num)
   {
     import std.stdio : writefln;
     this.result = num^^pow;
     writefln("%s", result);
   }
   void reset() {}
}

void main()
{
   auto square = POW!127(2); // "16129"
   //square.init; // Error: `POW(0)` has no effect
   square.writefln!"%s"; // POW!cast(byte)127(16129)
}
```

SDB at 79


More information about the Digitalmars-d mailing list