std.algorithm.joiner unexpected behavior

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 31 11:41:12 PDT 2017


On Thu, Aug 31, 2017 at 06:26:33PM +0000, Sergei Degtiarev via Digitalmars-d-learn wrote:
[...]
> 	File[] files;
> 	....
> 	foreach(ln; joiner(files.map!(a => a.byLine)))
> 		writeln(ln);

You probably want to use byLineCopy instead.

The problem here is that .byLine returns a transient range (i.e., the
value returned by .front changes after .popFront is called), which can
cause unexpected behaviour when used with certain algorithms.


T

-- 
I don't trust computers, I've spent too long programming to think that they can get anything right. -- James Miller


More information about the Digitalmars-d-learn mailing list