[Issue 19980] File.byLine skips first line in some cases when used inside map!()

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 17 22:42:04 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19980

--- Comment #1 from Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> ---
There's a bunch of things going on here:

1. byLine pops its front eagerly, which means merely constructing a byLine will
advance the file pointer.

2. files.map!(f => f.byLine) creates a range whose .front instantiates a new
byLine instance, thus advancing the file pointer every time it is evaluated.
However, it is not an error to evaluate a range's front multiple times, so
there is no bug in tee / each / joiner.

3. Additionally, byLine (ByLineImpl) instances do not each have their own file
pointer, which means that if you have more than one byLine instance attached to
the same file, advancing one will also advance all others. (Not sure if we
should fix this, as it is possible to imagine code relying on this.)

--


More information about the Digitalmars-d-bugs mailing list