RFC on range design for D2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Sep 10 11:33:26 PDT 2008


Bill Baxter wrote:
> On Thu, Sep 11, 2008 at 2:44 AM, Andrei Alexandrescu
> 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?

A function only needing one iterator is a chymera. It can't move it any 
direction. To such a function you pass a pointer or reference to the 
object you want to manipulate directly. What's there to not like about it.

> 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.

I think you get a lot more insight by actually sitting down and 
rewriting a part of std.algorithm, and/or write some more meaningful 
algorithms with your abstraction of choice. When I started doing so I 
had no idea of what range primitives I need. And just like you now, I 
kept on hypothesizing in the dark on whether I need this and whether I 
need that. When you hypothesize in the dark the number of primitive 
things you need really grows unbounded, because there's always some 
unrealized imaginary need you want to satisfy. To carry the discussion 
on equal footing you need to do some of that work. Otherwise you will 
keep on coming with hypothetical situations of unverifiable likelihood, 
and I will have little meaningful retort to put forth.

Speaking of which, a great merit of Stepanov is that he showed what a 
great host of algorithms can be implemented with a precise and narrow 
interface. We all knew how to rotate elements in an array. He showed how 
to rotate elements in a singly-linked list.


Andrei



More information about the Digitalmars-d-announce mailing list