Denis Koroskin wrote:
On Mon, 30 Nov 2009 18:25:41 +0300, Andrei Alexandrescu <seewebsiteforem...@erdani.org> wrote:

retard wrote:
Mon, 30 Nov 2009 12:01:22 +0100, Ary Borenszweig wrote:

KennyTM~ wrote:
By
far the two most important pieces of I/O functionality I need are:

1.  Read a text file line-by-line.
foreach (line; new Lines!(char) (new File ("foobar.txt")))
   Cout (line).newline;
}


yuck.
Yuck?? I find that code very elegant. How would you like it to be?
 I guess something like this:
 JustDoItWith("foobar.txt") {
  ...
}

foreach (char[] line; File("text.txt").byLine()) {
    ...
}

Efficient, flexible, convenient. Closes automatically the file, too, which Tango seems doesn't.


Andrei

If it closes file automatically, then why do you close it explicitly in slurp?

Because a compiler bug prevented the destructor from functioning correctly. The manual close does no harm now but of course should be removed.

The code is almost the same except that "Lines" class works with any Input Stream (memory stream, file stream, network stream, pipe, i/o device etc).

I hope we'd be able to add such streams to Phobos too, perhaps using your networking library for transport.


Andrei

Reply via email to