std.container & ranges

Kagamin spam at here.lot
Tue Nov 1 04:34:43 PDT 2011


Steven Schveighoffer Wrote:

> ahem, using dcollections:
> 
> foreach(ref doRemove, cell; &organism.purge)
>      doRemove = cell.x == x && cell.y == y;
> 
> complexity: O(n)

may be a generic iteration handler would be more useful?

foreach(ref handler, cell; &organism.each)
   if(cell.x == x && cell.y == y) handler.removeCurrent();

it could provide a whole api, say, you may want to have lookahead

foreach(ref handler, cell; &organism.each)
   if(cell.x == x && cell.y == y && handler.next.x==0)
      handler.removeCurrent();


More information about the Digitalmars-d-learn mailing list