tuple(...).each error; why does foreach work and std.algorithms.each doesn't ?

wjoe invalid at example.com
Tue Feb 11 18:55:45 UTC 2020


On Tuesday, 11 February 2020 at 18:21:11 UTC, Adam D. Ruppe wrote:
> On Tuesday, 11 February 2020 at 18:11:44 UTC, wjoe wrote:
>> In my mind, if something works with foreach, it should also 
>> work with std.algorithm.each.
>
> They are very different, the each thing only works for ranges 
> whereas foreach works with a variety of things.
>
>> How is 1) different from 2) ?
>
> The ARGS... is a compiler list and can have multiple different 
> types included. Moreover, it will auto-expand when you use it 
> to call a function etc.
>
> You can sometimes do [args] - with the [] around it to turn 
> into an array. Then you can .each it and so on. But they must 
> already be of compatible types to do that since an array 
> elements must all be the same thing.
>
> I would suggest just using foreach for this.

What's a compiler list... is that something like a tuple? or more 
like a macro expansion?
Or is it only valid to use in a foreach to take advantage of each 
item individually and for expansion in a function call ?
Is it possible to partially expand like:

void fn(int, uint) {}
and ARGS(string, int, uint)
and call fn(args[1..$]);

Is that possible?

as for the format function...foreach works as expected so I'll 
just keep that. Thanks for your fast reply :)


More information about the Digitalmars-d-learn mailing list