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

BoQsc vaidas.boqsc at gmail.com
Mon Sep 11 17:51:04 UTC 2023


https://docarchives.dlang.io/v2.073.0/spec/struct.html#struct-literal

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}`


Here is an example of what I would hope for to work but it surely 
does not work:

```
import std.stdio;

struct Options {
     bool silenceErrors = false;
}

void someFunction(Options option = {silenceErrors: false}){
	writeln(option);

}

void main() {
	someFunction();
}
```

Is it possible to make this part work in a simple way, maybe I'm 
using a wrong syntax here?
```
void someFunction(Options option = {silenceErrors: false}){
	writeln(option);

}
```


More information about the Digitalmars-d-learn mailing list