int x = auto
Ogi
ogion.art at gmail.com
Wed Mar 22 08:31:46 UTC 2023
Suggestion: allow implicit default-initialization using `type x =
auto` syntax. This is the same as `type x = type.init` and `type
x = type()`.
This will be especially handy for functions with optional
parameters.
Before:
```D
void fun(
int x = 0,
double x = double.nan,
bool flag = false,
string str = "",
void* ptr = null,
SomeStruct = SomeStruct(),
int[4] arr = [0, 0, 0, 0])
```
After:
```D
void fun(
int x = auto,
double f = auto,
bool flag = auto,
string str = auto,
void* ptr = auto,
SomeStruct = auto,
int[4] arr = auto)
```
Possible alternatives:
* `int x = init`: most obvious, but this would require making
`init` a reserved keyword.
* `int x = default`: more clear than `auto` but also quite longer.
* `int x = {}`: incompatible with D syntax.
More information about the Digitalmars-d
mailing list