All reasonable programs processing text files let the newline on the final line be completely optional. Having the line iterator silently ignore a final line with no terminating newline seems clearly wrong: It makes the line iterator useless for reasonable programs.
Returning a final empty line for files that *do* have a terminating newline, on the other hand, seems more harmless but still somewhat stupid.
Look at the line-based cat program:
foreach(Stdio.stdin->line_iterator();; string x) write("%s\n", x);
If I can choose between a line_iterator behaviour makes that program convert
"a\nb\n" --> "a\nb\n" "a\nb" --> "a\nb\n"
and a different behaviour that results in
"a\nb\n" --> "a\nb\n\n" (*) "a\nb" --> "a\nb\n"
I'd prefer the former (* is what you get if the iterator emits a final empty line). Even if it's different from division by "\n".
/ Niels Möller ()
Previous text:
2002-12-30 21:21: Subject: stdin->line_iterator
I wouldn't like that. That might be handy sometimes but is not intuitive. It's a DWIM.
/ Peter Bortas