New linked list

Walter Bright newshound at digitalmars.com
Thu May 11 15:16:23 PDT 2006


Sean Kelly wrote:
> *sigh*  I can see the reason for this, but it dramatically reduces the 
> utility of foreach for me, as it's a very common idiom to want to remove 
> elements during an iteration.  In fact, I already use this technique 
> quite a bit in Thread and ThreadGroup.  That aside, does this 
> restriction also exist for processing AA elements?

Yes - everything used as an aggregate in a foreach.

> I ask because this 
> is done on a dynamically allocated list of references rather than 
> against the AA itself, though I suppose that's implementation defined.

The idea is to enable the compiler to do aggressive loop optimizations, 
regardless of the aggregate type used, and regardless of whether it is 
user-defined or built-in.

>>> If so, I assume it would be okay to store a list of 'removed' items 
>>> until the iteration ends and them remove them all at once?
>>
>> Yes.
> 
> Thanks.  Assuming I did this, would it be technically legal to destroy 
> this list after the iteration ends but before opApply returns? 
> Otherwise, I'm not entirely certain how to go about processing the 
> removals.

I'm a bit reluctant to say yes on that, worrying that I'm forgetting 
something. What you can do is not use foreach, but just a for loop.



More information about the Digitalmars-d-announce mailing list