Bring back foreach int indexes
Liam McGillivray
yoshi.pit.link.mario at gmail.com
Sun Mar 24 21:05:01 UTC 2024
On Sunday, 24 March 2024 at 16:33:06 UTC, Walter Bright wrote:
> When size_t is 64 bits, the reason:
>
> foreach (int i; 0 .. array.length)
I suppose I wasn't clear enough. When I say I want it to work
without errors, I specifically meant in the following format:
```
foreach (uint i, entry; array)
```
I suppose for the other `foreach` format it would be nice too.
But for the latter, it would be as easy as removing a deprecation.
My position is that the latter format should be allowed and
removed from deprecation for the foreseeable future outside of
code marked `@safe`, but perhaps don't allow it in `@safe` code.
I don't know if it's ever considered acceptable practice for
runtime warnings to be automatically inserted into a program, but
perhaps for debug builds a runtime warning can be inserted
whenever the array is longer than, or perhaps more than 3/4 the
size allowed by the type of `i` (as in the code above).
But if it's still considered unacceptable to have the
now-deprecated format shown above be brought back as a language
feature, I suggest the following as a compromise:
```
foreach (cast uint i, entry; array)
```
and also
```
foreach (cast uint i; 0 .. array.length)
```
More information about the Digitalmars-d
mailing list