New linked list

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue May 23 23:47:21 PDT 2006


Boris Wang wrote: [edited upside-down post]
> "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. 
> 
 > why not make a feature:
 >
 >     safe foreach( Person p; ....)

If such a feature was to be implemented, I can think of a better 
(cleaner and more consistent with the rest of the language) syntax:

     foreach(Peron p; inout people)
     {
         // ...
     }

Why invent a new keyword when an old one (though in a different place) 
perfectly expresses what's going on?

	Frits van Bommel



More information about the Digitalmars-d-announce mailing list