std.array.array broken?

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Feb 1 14:52:23 PST 2014


On Saturday, 1 February 2014 at 22:47:54 UTC, deed wrote:
> Docs say:
> - std.stdio.byLine returns an input range
> - std.array.array takes an input range

Docs also say:

/**
Note:
Each $(D front) will not persist after $(D
popFront) is called, so the caller must copy its contents (e.g. by
calling $(D to!string)) if retention is needed.
*/

So you need to do a duplication for each element. Use this code:

-----
import std.stdio;
import std.array;
import std.algorithm;

void main()
{
     auto lines = File("test.d").byLine.map!(a => a.dup).array;
     writeln(lines);
}
-----


More information about the Digitalmars-d-learn mailing list