struct initializer
kdevel
kdevel at vogtner.de
Fri Dec 1 19:02:00 UTC 2023
On Wednesday, 29 November 2023 at 16:48:09 UTC, Paul Backus wrote:
> [...]
> If you're using a new enough compiler, it even supports named
> arguments:
>
> S3 fun2() { return S3(b: 2, a: 5); }
Indeed. Seems to be in dmd since 2.103.0 (2.102.2 didn't support
this syntax). Alas, the Change Log [1] remain silent about it.
```
commit 42609ae98e0f72a8d2154da50865bc5182c4b6b3
Author: Dennis <d[...]
Date: Tue Jan 17 13:08:30 2023 +0100
Add named arguments to struct literals (#14776)
* Add named argument parsing
[...]
```
The named parameters are not restricted to struct constructors:
```d
import std.stdio;
auto delta (int from, int to)
{
return to - from;
}
void main ()
{
writeln (delta (to: 8, from: 1));
}
```
```
$ dmd structinit.d
$ ./structinit
7
```
[1] https://dlang.org/changelog/2.103.0.html
More information about the Digitalmars-d-learn
mailing list