eliminate cast
BCS
ao at pathlink.com
Wed May 14 09:25:54 PDT 2008
Reply to Dee,
> There is a file data.txt with numbers:
>
> 345
> 5467
> 45
> 238
> ...
> And I want to load into an array of uint like this.
>
> auto sizes = map!
> (to!(uint, string))
> (compose!(split, q{cast(string) std.file.read(a)})("data.txt"));
>
> It works but cast is always bad ^_^. How can I eliminate cast? Is
> there function to read entire text file in string? Thank you, Dee Girl
>
IMHO in this case the cast is /not/ bad. It is an explicit documentation
of your intent. The file.read function knows nothing about what it is reading
and therefor returns ubyte[] to say "this is data" and the cast is the programer
saying "I known this is text".
More information about the Digitalmars-d
mailing list