DIP 1031--Deprecate Brace-Style Struct Initializers--Community Review Round 1 Discussion

Walter Bright newshound2 at digitalmars.com
Fri Feb 14 23:10:36 UTC 2020


On 2/14/2020 1:49 PM, Walter Bright wrote:
> On 2/14/2020 6:46 AM, Steven Schveighoffer wrote:
>> Now, imagine Vector2D and Moves are templated on type! Would be horrendous.
> 
> That's why D has alias declarations.

You can also do:

     auto v(float a, float b) { return Vector2D(x: a, y: b); }

and:

    Moves awsd = {items: [{x: 1, y: 0}, {x: 0, y: 1}, {x: -1, y: 0}, {x:0, y:-1}]};

becomes:

     auto awsd = Moves(items: [v(1,0), v(0,1), v(-1,0), v(0,-1)]);

voila!


More information about the Digitalmars-d mailing list