foreach counter now must be size_t ?

Nicholas Wilson iamthewilsonator at hotmail.com
Tue Feb 5 01:05:50 UTC 2019


On Monday, 4 February 2019 at 23:01:06 UTC, Nicholas Wilson wrote:
> On Monday, 4 February 2019 at 22:26:08 UTC, Johan Engelen wrote:
>> This code now gives a deprecation message (>= 2.084):
>> ```
>> void foo(int[] arr) {
>>     foreach (uint i, ref elem; arr) { }
>> }
>> ```
>> Deprecation: foreach: loop index implicitly converted from 
>> `size_t` to `uint`
>>
>> This is in contrast to the spec that says that "The index must 
>> be of int, uint, long or ulong type, it cannot be ref, and it 
>> is set to be the index of the array element."
>> https://dlang.org/spec/statement.html#foreach_over_arrays
>>
>> Did someone forget to update the spec? Or is it a frontend bug?
>>
>> -Johan
>
> Thats a spec problem. The behaviour is very much deliberate.

https://github.com/dlang/dlang.org/pull/2565/


More information about the Digitalmars-d mailing list