On Tuesday, 11 February 2014 at 10:10:27 UTC, Regan Heath wrote:
Things like this should "just work"..
File input ...
auto range = input.byLine();
while(!range.empty)
{
range.popFront();
foreach (i, line; range.take(4)) //Error: cannot infer
argument types
{
..etc..
}
range.popFront();
}
Tried adding 'int' and 'char[]' or 'auto' .. no dice.
Can someone explain why this fails, and if this is a permanent
or temporary limitation of D/MD.
R
In case the other replies weren't clear enough. A range does not
have an index.
What do you expect 'i' to be? Is it the line number? Is it the
index within the line where 'take' begins? Where 'take' stops?
There is a feature of foreach and tuple() which results in the
tuple getting expanded automatically.
byLine has its own issues with reuse of the buffer, it isn't
inherent to ranges. I haven't really used it (needed it from
std.process), when I wanted to read a large file I went with
wrapping std.mmap:
https://github.com/JesseKPhillips/libosm/blob/master/source/util/filerange.d