std.array oddness

earthfront via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 12 21:15:08 PST 2014


Hello!
I was attempting project euler problem 22 and seeing something
weird going on with the array function in std.array.
I made the following code to demonstrate.

Given names.txt:
------------------
"MARY","PATRICIA","LINDA","BARBARA","ELIZABETH"
------------------

and code:
------------------
import std.array,std.stdio;

void main()
{
       { // Correct
           auto names = File("names.txt","r")
               .byLine!(char,char)(KeepTerminator.no,',');

           foreach(char[] name; names ){ writeln( name ); }
       }
       { // Converting to "array" borks the thing
           auto names = File("names.txt","r")
               .byLine!(char,char)(KeepTerminator.no,',')
               .array;

           foreach( char[] name; names){ writeln( name ); }
       }
}
------------------

I get the following output:
------------------
➜ euler rdmd ./stdArrayBug.d
"MARY"
"PATRICIA"
"LINDA"
"BARBARA"
"ELIZABETH"


"ELIZA
"ELIZABETH
"ELIZAB
"ELIZABET
"ELIZABETH"
------------------

Am I using array incorrectly?
I searched bugzilla and didn't see anything pertaining to this
issue.
Should I file a bug?

DMD64 D Compiler v2.066.1
Ubuntu Linux

Thanks!


More information about the Digitalmars-d-learn mailing list