Shout out to D at cppcon, when talkign about ranges.

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Thu Oct 8 07:46:05 PDT 2015


On Thursday, 8 October 2015 at 14:36:03 UTC, Kagamin wrote:
> On Thursday, 8 October 2015 at 13:10:24 UTC, John Colvin wrote:
>> What you're effectively describing is a trio of iterators 
>> wrapped to give an interface of two linked ranges. popFront 
>> grows the first one and shrinks the second. I'd be interested 
>> to see how to construct that, given a generic range as input.
>
> The C++ example doesn't work with generic iterators, it needs a 
> specific ability to iterate in both directions, hence a 
> bidirectional range.

Of course.

> The way ranges are used for iteration, they can be seen as 
> adapters for iterators providing various consistent interfaces 
> depending on their capabilities. In this example we need a 
> bidirectional range that can go back and forth, one way to do 
> it is to provide undo mechanism like undoPopFront and 
> frontUndoEmpty to allow the range grow back, thus remaining a 
> range that is a list of items and not an iterator.

I much prefer this second version:

> Another way is to provide a reverse range of previously popped 
> items - this can be seen as iterator or not, more like a range 
> with history rather than an undoable input range, so maybe the 
> getter should be `history`.

my question is: How, in practice, does one take a bidirectional 
range and make one of these new things? I foresee some 
difficulty, but perhaps I'm just not being imaginative enough.


More information about the Digitalmars-d mailing list