Default struct constructor

bitwise bitwise.pvt at gmail.com
Thu Feb 7 15:02:09 UTC 2019


On Wednesday, 6 February 2019 at 23:17:31 UTC, Jonathan M Davis 
wrote:
> On Wednesday, February 6, 2019 7:49:28 AM MST bitwise via 
> Digitalmars-d wrote:
>> [...]
>
> If that's what you want, then you can just use a static opCall. 
> e.g.
>
> struct S {
>     static S opCall() { ... }
> }
> auto s = S();
>
> The only real restriction is that you can't declare any 
> constructors if you have any static opCall functions declared.
>
> - Jonathan M Davis

Sorry - my example was pretty bad.

I'm suggesting that this(void) be a dynamic alternative to T.init.

Current:

struct S { int n; }
S s = void;
s.n = 1;

Suggested:

struct S { int n; this(void){ n = 1; } }
S s;   // this(void) invoked here and T.init not used


More information about the Digitalmars-d mailing list