How should to!string handle infinite ranges?
Steven Schveighoffer
schveiguy at gmail.com
Tue Mar 4 12:46:31 UTC 2025
On Tuesday, 4 March 2025 at 10:38:24 UTC, Paul Backus wrote:
> We're currently having a discussion about this [on Github][1].
> The way I see it, there are two reasonable choices:
>
> 1. Return a finite string indicating that the range was
> infinite. For example, `"[1, 2, 3, ...]"`.
>
> 2. Fail to compile and print a meaningful error message using
> `static assert`. For example, `Can't convert an infinite range
> to a string`.
>
> As a D programmer, which behavior would you find more useful or
> less surprising?
>
> [1]: https://github.com/dlang/phobos/pull/10660
I'd expect a compiler failure over an assumption as to what the
user wants.
That being said, I think it could be an option for to!string on a
range to truncate after a specific number of items.
I'll put a note in the PR.
-Steve
More information about the Digitalmars-d
mailing list