how to assign multiple variables at once by unpacking array?

mw m at g.c
Sun Oct 8 19:49:50 UTC 2023


On Sunday, 8 October 2023 at 07:45:56 UTC, Andrea Fontana wrote:
> On Sunday, 8 October 2023 at 07:44:04 UTC, Andrea Fontana wrote:
>>
>> ```
>>     int a,b,c;
>>
>>     "1,2,3"
>>         .splitter(',')
>>         .zip(only(&a, &b, &c))
>>         .each!(x => *x[1] = x[0].to!int);
>>
>>     writeln(a, b, c);
>> ```
>
> or:
>
> ```
>     int a,b,c;
>
>     only(&a, &b, &c)
>         .zip("1,2,3".splitter(','))
>         .each!(x => *x[0] = x[1].to!int);
>
>     writeln(a, b, c);
> ```

Nice.


More information about the Digitalmars-d-learn mailing list