New linked list
Walter Bright
newshound at digitalmars.com
Thu May 11 09:52:10 PDT 2006
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.
More information about the Digitalmars-d-announce
mailing list