New linked list
Chris Miller
chris at dprogramming.com
Thu May 11 12:28:39 PDT 2006
On Thu, 11 May 2006 15:06:23 -0400, Walter Bright
<newshound at digitalmars.com> wrote:
> Sean Kelly wrote:
>> Walter Bright wrote:
>>> Sean Kelly wrote:
>>>> Very cool. One thing... does this work:
>>>>
>>>> foreach( Person p; per.each )
>>>> {
>>>> if( p.age > 50 )
>>>> p.listRemove();
>>>> }
>>>>
>>>> ie. can you remove elements within a foreach?
>>>
>>> It's undefined behavior. foreach is entitled to assume that the
>>> aggregate is a loop invariant, although the contents of the
>>> aggregate's elements can change. This precludes things like resizing
>>> an array inside a foreach, etc.
>> Even for a class that defines an opApply?
>
> Yes. The idea is to apply uniform semantics.
Makes sense. Perhaps I should add a filter() function that calls back a
delegate for each item and allows you to remove items safely.
More information about the Digitalmars-d-announce
mailing list