Nicer syntax for constructors

Adam D. Ruppe destructionator at gmail.com
Sun Nov 18 20:20:50 UTC 2018


class A {
   int a;
   string b;
   float c;

   this(typeof(this.tupleof) args) {
     this.tupleof = args;
   }
}


auto a = new A(4, "foo", 1.5);


Of course, that assumes none of the internal types are const, 
that complicates things, and it assumes you want to set them all 
at once. It also doesn't work quite right with inheritance, but 
you can make that work by combining the base class tuple if you 
want.

Keep in mind you can also slice tuples if you want a subset of 
the members.


More information about the Digitalmars-d mailing list