Can we drop static struct initializers?

Walter Bright newshound1 at digitalmars.com
Fri Nov 20 15:34:10 PST 2009


Bill Baxter wrote:
> Here's one thing I just found:
> struct constructors don't work at compile-time:
> 
> struct Struct
> {
>     this(int _n, float _x) {
>         n = _n; x = _x;
>     }
>     int n;
>     float x;
> }
> 
> enum A = Struct(1,2);
> 
> // Error: cannot evaluate ((Struct __ctmp1;
> // ) , __ctmp1).this(1,2F) at compile time
> 
> The C-style initializer works.
> static opCall works too.
> 
> But if that bug is fixed, then I can't think of a reason to have the
> classic C-style no-colons syntax.

It isn't a bug. You simply don't need constructors that progressively 
assign parameters to fields.

    Struct(1,2);

works just fine without that constructor being defined.



More information about the Digitalmars-d mailing list