RFC on range design for D2

Bill Baxter wbaxter at gmail.com
Wed Sep 10 10:56:14 PDT 2008


On Thu, Sep 11, 2008 at 2:44 AM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> Steven Schveighoffer wrote:
>>
>> "Andrei Alexandrescu" wrote
>>>
>>> Bill Baxter wrote:
>>>>
>>>> But upon further reflection I think it may be that it's just not what
>>>> I would call a bidirectional range.  By that I mean it's not good at
>>>> solving the problems that a bidirectional iterator in C++ is good for.
>>>
>>> It's good. I proved that constructively for std.algorithm, which of
>>> course doesn't stand. But I've also proved it theoretically informally to
>>> myself. Please imagine an algorithm that bidir iterators do and bidir ranges
>>> don't.
>>
>> Any iterative algorithm where the search might go up or down might be a
>> candidate.  Although I think you have a hard time showing one that needs
>> strictly bidirectional iterators and not random access iterators.  Perhaps a
>> stream represented as a linked list?  Imagine a video stream coming in,
>> where the player buffers 10 seconds of data for decoding, and keeps 10
>> seconds of data buffered behind the current spot.  If the user pauses the
>> video, then wants to play backwards for 5 seconds, what kind of structure
>> would you use to represent the 'current point in time'?  A bidir range
>> doesn't cut it, because it can only move one direction at a time.
>
> Of course it does. You just remember the leftmost point in time you need to
> remember. Then you use range primitives to get to where you want. Maybe a
> better abstraction for all that is a sliding window though.

Cognitive load...
What if I want to write a nice standalone function that takes a
pointer to where we are and manipulates it?  I have to pass that
function two iterators I suppose?  One is (begin,current) the other
(current,end), and as I iterate I have to move both the second of the
first and the first of second?  All just to do something that should
be trivial with a linked list.

I agree that your pinch range is needed, but I also see a need for
something that maps more directly onto the features of a doubly linked
list.

--bb


More information about the Digitalmars-d-announce mailing list