Revised RFC on range design for D2

Sergey Gromov snake.scaly at gmail.com
Sat Sep 13 03:02:42 PDT 2008


Sean Kelly <sean at invisibleduck.org> wrote:
> Walter Bright wrote:
> > Andrei Alexandrescu wrote:
> >> Ary Borenszweig wrote:
> >>> - Is it possible to add elements to a range? Suppose a linked list, 
> >>> you want to traverse it's elements until a condition is met on an 
> >>> element, and then add something after it. Or before it. I see there's 
> >>> "put", but it also says "An output range models a one-pass forward 
> >>> writing iteration.", so I think it's not the same.
> >>
> >> Never. Ranges never grow. You need access to the "mother" container, 
> >> which will offer primitives for insertion and removal of elements.
> > 
> > I agree. I don't think it is ever a good idea to try to add/remove 
> > elements of a container while iterating over it. foreach disallows it.
> 
> In fact, it may not even be possible to remove elements of a container 
> outside the inspection loop.  For example, let's say the container is 
> actually a SQL resultset and the iterator is a cursor.  It's easy to 
> mark a row as 'deleted' in this instance, but storing information to 
> perform a deletion later often simply can't be done.  Though I suppose 
> you could argue that the 'container' abstraction may be inappropriate 
> for such temporal data.

I think that the Input Range abstraction works fine here.  That is, the 
'head' of the Select range is actually a cursor object which has a 
markForDeletion() method.  It may be bad to allow deletion in generic 
case, but you can always have a special case to work around.


More information about the Digitalmars-d-announce mailing list