partition(range, leftsubrange) or partition(range, rightsubrange)

Bill Baxter wbaxter at gmail.com
Wed Sep 10 19:53:04 PDT 2008


On Thu, Sep 11, 2008 at 11:41 AM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> superdan wrote:
>>
>> 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*.


Agreed completely.  That's basically what I just got finished sayin'.  :-)


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

Yep.

--bb


More information about the Digitalmars-d-announce mailing list