New linked list
Boris Wang
nano.kago at hotmail.com
Tue May 23 20:04:38 PDT 2006
why not make a feature:
safe foreach( Person p; ....)
"Walter Bright" <newshound at digitalmars.com> 写入消息新闻:e3vq3l$1rp5$3 at digitaldaemon.com...
> 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