static array is not a range

bachmeier no at spam.net
Tue Jan 9 13:22:24 UTC 2024


On Tuesday, 9 January 2024 at 10:11:35 UTC, Alexibu wrote:
> It looks like isInputRange is false for arrays with fixed 
> length by design.
>
> I can do:
>
> ```d
> float[4] arr;
> foreach(x;arr)
>    writefln("%s",x)
> ```
> but not :
>
> ```d
> arr.each!(a => a.writefln("%s",a));
> ```
> Is there a good reason for this ?
> It took my a long time to figure out.

Jonathan's been giving you good general information about this. 
I'm curious about your partial example. If I fix the writefln 
call, it works.

```
import std;
float[4] arr;
void main() {
   arr[0] = 1;
   arr[1] = 2;
   arr[2] = 3;
   arr[3] = 4;
   arr.each!(a => "%s".writefln(a));
}
```


More information about the Digitalmars-d-learn mailing list