Why does File.byLine() return char[] and not string

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 16 05:43:57 PDT 2015


On Friday, 16 October 2015 at 10:38:52 UTC, Shriramana Sharma 
wrote:
> Is there a particular reason that File.byLine() returns char[] 
> and not string i.e. immutable(char)[]? Is it just to avoid 
> being overly restrictive? It seems that having to .idup it is 
> inefficient...

byLine reuses an internal buffer for each line which gets 
overwritten each iteration. The fact that it returns char instead 
of string is meant to signal this to the user, to tell them that 
the value they're getting back is mutable and subject to change.


More information about the Digitalmars-d-learn mailing list