Bring back foreach int indexes
Hipreme
msnmancini at hotmail.com
Thu Nov 30 11:01:15 UTC 2023
On Thursday, 30 November 2023 at 10:49:47 UTC, IGotD- wrote:
> On Wednesday, 29 November 2023 at 21:47:09 UTC, bachmeier wrote:
>>
>> In the case you're talking about, you could do
>>
>> ```
>> foreach(_idx, v; arr) {
>> int idx = cast(int) _idx;
>> }
>> ```
>>
>> I don't mind ugly and verbose code if there's sufficient
>> benefit. There's no benefit in this case.
>
> I don't understand why this is not an OK solution instead
> adding yet another lowering for the special case of using int
> instead of size_t. Right now in D indexes are size_t and should
> be the default.
>
> This feels more like a D3 discussion if indexes should be int
> or size_t.
That is because there is no reason to have explicit conversions
everywhere, they are overly verbose and ugly. And this is one of
the reasons because I don't use `foreach` in my code. Good old
`for` loop can let you decide the type. Modern programming
languages should reduce friction, and not increase it.
More information about the Digitalmars-d
mailing list