Order of evaluation for named arguments

Ogion ogion.art at gmail.com
Tue Apr 1 09:05:59 UTC 2025


On Sunday, 30 March 2025 at 09:14:49 UTC, Daniel N wrote:
> I think you are overlooking one important detail, 
> StructInitializer, it must match named arguments and 
> fortunately it does.
>
>
> ```d
> import std.stdio;
> struct S { int a, b; }
>
> int fun(int v)
> {
>     v.writeln;
>     return v;
> }
>
> void main()
> {
> 	S r;
> 	S s = { b:fun(1), a:fun(2) };
> }
> ```
> 2
> 1

Same with ArrayInitializer:
  ```D
import std.stdio;

int fun(int v)
{
     v.writeln;
     return v;
}

void main() {
	int[2] a = [ 1:fun(1), 0:fun(2) ];
}
```
1
2



More information about the Digitalmars-d mailing list