Setting struct as default parameter of a function using struct literal?

H. S. Teoh hsteoh at qfbox.info
Mon Sep 11 20:17:09 UTC 2023


On Mon, Sep 11, 2023 at 07:59:37PM +0000, ryuukk_ via Digitalmars-d-learn wrote:
[...]
> Recent version of D added named arguments so you can do something
> like:
> 
> ```D
> void someFunction(Options option = Options(silenceErrors: false))
> ```
> 
> I don't like the useless repeating "option option option", but that's
> D for you

Someone should seriously come up with a way of eliminating the repeated
type name in default parameters.  It's a constant fly in my otherwise
tasty soup of D.  Every time I have to type that I think about how nice
it would be if we could just write

	void someFunction(Options option = .init) {...}

and be done with it.  Or else:

	void someFunction(auto options = Options.init) {}

though this is not as good because the `auto` may make it hard to parse
function declarations.


T

-- 
Life would be easier if I had the source code. -- YHL


More information about the Digitalmars-d-learn mailing list