Is there a nice syntax to achieve optional named parameters?

Dukc ajieskola at gmail.com
Wed Jan 16 11:21:53 UTC 2019


On Tuesday, 15 January 2019 at 11:14:54 UTC, John Burton wrote:
> This is ok, but I'm not so keen on separating the creation and 
> construction like this.
> Is there a better way that's not ugly?

You can make the constructor a template that takes a single 
struct of arbitrary, and inspects (at compile time) if it has 
fields with certain names and types. Then, when constructing, you 
feed that constructor a std.typecons.Tuple with named fields. Or 
alternatively, use a separate builder type that makes a good 
struct to feed for the window constructor.

The disadvantage is that you cannot link the constructor template 
directly for external programs. But for that, you define some 
sort of wrapper function that always takes all the parameters and 
then calls the template.


More information about the Digitalmars-d-learn mailing list