partition(range, leftsubrange) or partition(range, rightsubrange)
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Sep 10 19:41:03 PDT 2008
superdan wrote:
> got a question on this range stuff. in stl partition is
> partition(begin, mid, end). neat. in std.algorithm partition is
> partition(range, mid). so-so. never like it mucho. in the new stuff
> with ranges n all there are two choices partition(range,
> leftsubrange) or partition(range, rightsubrange). question is, is
> there a better choice between the two or are they just the same.
> would be cool to have a clear rule with some advantage. and that's
> easy to remember too.
>
> like steve i think ranges are cool n all but fraid iterators are
> still good at sumthin'. either-way choices ain't a good sign.
I think I have an answer. All algorithms supposed to take begin, middle,
and end should take range(begin, end) and range(middle, end) and not any
other combination. Moreover, whenever a collection can choose to returns
a subrange or another, it should return the range to the right.
This is because right-open ranges are the most general, e.g.
singly-linked lists with range==Node* (or other similar
sentinel-terminated collections).
Imposing a range of the kind range(begin, middle) would make that
algorithm not work for singly-linked list unless they implement a "fat"
range containing two Node*.
So rotate should be:
R rotate(R)(R range, R subrange);
Description: moves subrange to the front of range, and whatever was in
front of the subrange right after it. Preconditions: subrange is a
subrange of range (duh). Returns the range after the moved subrange. (In
fact I already mentioned I plan to give rotate the more descriptive name
moveToFront.)
Makes sense?
Andrei
More information about the Digitalmars-d-announce
mailing list