std.partition is fucked

Sean Kelly sean at invisibleduck.org
Wed May 13 14:44:05 PDT 2009


== Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
>
> As a general rule, when they could return either the left or the right
> subrange of a range, functions in std.algorithm return the right range.
> This is because sentinel-terminated ranges cannot express the
> left-hand-side range.

Gotcha.  That's unfortunate, but makes perfect sense.

> Partition is in fact the perfect example because it works with forward
> ranges. If you want to partition a singly-linked list, you'd have to
> return the right-hand sublist. There's nothing else you could possibly
> return! If you wanted to return the left-hand sublist, you'd have to
> return a different type of range (something like "list up to this node").
> So for generality's sake, whenever you have a choice, return the
> right-hand part of a range.

It looks like there may be another bug in partition then.  The static else
clause (ss == SwapStrategy.unstable) is supposed to work for forward
ranges but it calls popBack().  It looks like only the semistable option
is actually available to forward ranges.  Is this correct?

> There is growing interest in defining additional ranges that express (at
> a cost) things like "the portion of a singly-linked list starting at
> node X and ending at node Y". For example, people want to do a find()
> and then deal with the portion _before_ the found element. I'd love to
> discuss that further, but I guess I'll have to wait for the d.next
> newsgroup. :oD

Yeah, it would be great if it were possible to slice and dice a range in
any manner of different ways.



More information about the Digitalmars-d mailing list