Structs are Not Plain: A call for empty struct constructors

nkm1 t4nk074 at
Thu Sep 19 11:04:40 UTC 2019

On Thursday, 19 September 2019 at 09:02:39 UTC, FeepingCreature 
> What else follows from this? We can't use immutable - because 
> immutable fields can only be set in a proper constructor. We 
> could do horrible workarounds like `Fixture(null)`, but that's 
> just making a bad situation worse.

I have no idea why default constructors are disallowed, but your 
factory doesn't need to be opCall(). E.g., this seems to me a 
reasonable solution:

struct Fixture
     int a, b;
     static Fixture Default() { return Fixture(1, 2); }

void main()
     import std.stdio;

     with (Fixture.Default) {

(I actually like it more than default ctors, which is, of course, 
not a reason to disallow default ctors).

More information about the Digitalmars-d mailing list