containers, iteration, and removal
    Steven Schveighoffer 
    schveiguy at yahoo.com
       
    Fri Aug 24 10:35:57 PDT 2012
    
    
  
On Wed, 01 Aug 2012 03:44:47 -0400, Ellery Newcomer  
<ellery-newcomer at utulsa.edu> wrote:
> Hello.
>
> Today I was thinking about Java. Specifically, java.util.Iterator and  
> the pattern
>
> while(iter.hasNext()) {
> 	Object item = iter.next();
> 	if(predicate(item)) {
> 		iter.remove();
> 	}
> }
>
> You can do this in Java.
You can do this just as easy in dcollections:
foreach(bool doRemove, item; container)
{
    doRemove = predicate(item);
}
In fact, this little feature is one of the major reasons I wanted to  
create a collections library.  Tango's container library was modeled after  
Doug Lea's (not the Java adaptation of it), and it did not include a way  
to remove during iteration.
-Steve
    
    
More information about the Digitalmars-d
mailing list