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

cc cc at nevernet.com
Wed Sep 13 01:55:41 UTC 2023


On Monday, 11 September 2023 at 17:51:04 UTC, BoQsc wrote:
> I would like to set function's default struct for a function in 
> a way that it would be visible for the reader to see what 
> options are set. Something like `Options option = 
> {silenceErrors: false}`

If the function's defaults will always match the default 
initializers of the struct itself,
```d
struct Options {
     bool silenceErrors = false;
}
void someFunction(Options option = Options.init) {
	writeln(option);
}
```
else:
```d
struct Options {
     bool silenceErrors = false;
}
void someFunction(Options option = Options(silenceErrors: true)) {
	writeln(option);
}
```



More information about the Digitalmars-d-learn mailing list