Is there a nice syntax to achieve optional named parameters?
John Burton
john.burton at jbmail.com
Thu Jan 17 10:21:28 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:
>> [...]
>
> Let me throw this idea here:
>
>
> struct Config
> {
> string title;
> int width;
> }
>
> struct Window
> {
> this(Config config)
> {
> //use static foreach magic to set everything :P
> }
> }
>
> auto NewWindow( alias code )()
> {
> mixin("Config config = {"~code~"};");
> return Window(config);
> }
>
> //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{};
>
>
> :)
Oh that's interesting!
More information about the Digitalmars-d-learn
mailing list