Is removing elements of AA in foreach loop safe?

Ferhat Kurtulmuş aferust at
Tue Sep 3 20:06:27 UTC 2019

On Thursday, 29 August 2019 at 10:11:58 UTC, berni wrote:
> Iterating of some structure and removing elements thereby is 
> always errorprone and should be avoided. But: In case of AA, 
> I've got the feeling, that it might be safe:
>> foreach (k,v;ways)
>>     if (v.empty)
>>         ways.remove(k);
> Do you agree? Or is there a better way to achieve this?

I know, it is foreach loop in question. How about using a reverse 
for loop like:

for (size_t i = arr.length ; i-- > 0 ; ){

More information about the Digitalmars-d-learn mailing list