Is there a nice syntax to achieve optional named parameters?

kdevel kdevel at vogtner.de
Thu Jan 17 17:33:16 UTC 2019


On Thursday, 17 January 2019 at 01:43:42 UTC, SrMordred wrote:
> On Tuesday, 15 January 2019 at 11:14:54 UTC, John Burton wrote:

[...]

>> auto window = Window();
>> window.title = "My Window";
>> window.width = 1000;
>> window.create();

[...]

>> Is there a better way that's not ugly?

[...]

> //usage:
> auto a = NewWindow!q{ title : "MainTitle" };
> auto b = NewWindow!q{ title : "MainTitle", width : 800 };
> auto c = NewWindow!q{ width : 1000 };
> auto d = NewWindow!q{};
>
>
> :)

Put a semicolon instead of the comma in the line "auto b ..." and 
compile.


More information about the Digitalmars-d-learn mailing list