std.stdio.writeln should not accept infinite ranges?
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Thu Nov 12 17:19:22 PST 2015
On 11/12/2015 08:18 PM, Xinok wrote:
> The following code compiles and runs:
>
> import std.stdio, std.random;
>
> void main()
> {
> writeln(rndGen);
> }
>
> Since rndGen is an infinite range, this code runs forever. It seems to
> be that we need to add a check for isInfinite on writeln and other
> related functions.
>
> Does anybody have a use case where this is actually practical? I don't
> see a reason for allowing infinite ranges here, considering how easy it
> is to write "range.take(n)".
Piping a program that produces infinite output into less is practical.
-- Andrei
More information about the Digitalmars-d
mailing list