RFC on range design for D2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Sep 8 20:43:11 PDT 2008


Michel Fortin wrote:
> On 2008-09-08 17:50:54 -0400, Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org> said:
> 
>> feedback would be highly appreciated. See:
>>
>> http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.html
> 
> That looks great. I want to suggest renaming a few functions to make 
> them more consistant and (hopefully) more expressive, as I see I'm not 
> the only one frowning on them.
> 
> So right now you're defining this:
> 
> r.getNext
> r.putNext
> 
> r.left
> r.next
> rightUnion(r, s)
> rightDiff(r, s)
> 
> r.right
> r.pop
> leftUnion(r, s)
> leftDiff(r, s)
> 
> Here's my alternate naming proposal:
> 
> r.headNext
> r.putNext
> 
> r.head
> r.next
> r.nextUntil(s)
> r.nextAfter(s)
> 
> r.rear
> r.pull
> r.pullUntil(s)
> r.pullAfter(s)
> 
> Note that r.headNext is literally r.head followed by r.next when you 
> have a forward iterator.  You could also add "rearPull" to bidirectional 
> ranges if you wanted. :-)
> 
> The syntax is a little different for binary functions (union, diff) as I 
> changed them to members to make things easier to read and more in line 
> with the regular next and pull.

I like the alternate names quite some. One thing, however, is that head 
and rear are not near-antonyms (which ideally they should be). Maybe 
front and rear would be an improvement. (STL uses front and back). Also, 
I may be dirty-minded, but somehow headNext just sounds... bad :o).

I like the intersection functions as members because they clarify the 
relationship between the two ranges, which is asymmetric. I will 
definitely heed this suggestion. "Until" suggests iteration, however, 
which it shouldn't be (should be constant time) so maybe "nextTo" or 
something could be more suggestive.

This is going somewhere!


Andrei


More information about the Digitalmars-d-announce mailing list