std.algorithm.joiner unexpected behavior

Jesse Phillips via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 31 11:43:40 PDT 2017


On Thursday, 31 August 2017 at 18:26:33 UTC, Sergei Degtiarev 
wrote:
> Hi,
> I tried to create a simple range concatenating several files, 
> something like this:
>
> 	File[] files;
> 	....
> 	foreach(ln; joiner(files.map!(a => a.byLine)))
> 		writeln(ln);
>
> and I see every first line of each file is missing.
> However, when I do same thing with separator:
>
> 	char[][] separator=["**** new file ****".dup];
> 	foreach(ln; joiner(files.map!(a => a.byLine), separator))
> 		writeln(ln);
>
> everything works fine, both separator and first lines are 
> printed.
> It looks pretty much as a bug for me, but I'm not sure I use it 
> correctly.

Doesn't byLine() reuse a buffer, joiner probably caches the first 
line and calls .popFront()


More information about the Digitalmars-d-learn mailing list