std.array oddness
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Dec 12 22:40:28 PST 2014
On Sat, 13 Dec 2014 05:15:08 +0000
earthfront via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> Am I using array incorrectly?
no, you are using `.byLine` incorrectly. ;-) `.byLine` reuses it's
internal buffer for each line, so you have to copy that buffer. like
this:
import std.array, std.stdio;
void main () {
// Converting to "array" borks the thing
import std.algorithm : map;
auto names = File("names.txt")
.byLine!(char,char)(KeepTerminator.no, ',')
.map!"a.idup"
.array;
foreach (name; names) writeln(name);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141213/226f376c/attachment.sig>
More information about the Digitalmars-d-learn
mailing list