Nicer syntax for constructors

bauss jj_1337 at live.dk
Mon Nov 19 16:15:38 UTC 2018


On Sunday, 18 November 2018 at 20:20:50 UTC, Adam D. Ruppe wrote:
> 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.

The problem with your solution is if you just want a and b 
assigned.


More information about the Digitalmars-d mailing list