Array of byLineCopy ranges behaves as they are byLine

HaraldZealot harald_zealot at tut.by
Mon Mar 11 17:33:31 UTC 2019


On Monday, 11 March 2019 at 17:04:56 UTC, ag0aep6g wrote:
>
> To avoid the re-evaluation, assign `ranges[0]` to a variable 
> before using it:
>
>     auto lines = ranges[0];
>     writeln(lines.front);
>     writeln(lines.front);
>     writeln(lines.front);
>
> That should print the same line three times.

Ah yes, I forget about laziness of `map`. BTW, I have found other 
solution, which is more fit to my initial intention.

```d
ReturnType!(std.stdio.File.byLineCopy!(char, immutable(char)))[] 
ranges;
foreach(filename; args[1 .. $])
{
     ranges ~= File(filename, "r").byLineCopy;
}
```


More information about the Digitalmars-d-learn mailing list