www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10706] New: Functions that require a sorted range to take a SortedRange?


           Summary: Functions that require a sorted range to take a
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc

--- Comment #0 from bearophile_hugs eml.cc 2013-07-23 13:00:25 PDT ---
In Phobos we have std.range.assumeSorted, std.algorithm.isSorted, and various
sort() functions that return a SortedRange. If you call a release() on a
SortedRange you get the range that's under it (often an array).

(A SortedRange was so far only a RandomAccessRange, but lately the it has
emerged the idea that a ForwardRange is OK too, so it will probably be expanded
for all input ranges.)

So isn't it good to have the "set operations" (that actually work on _sorted
bags_, so their name is in my opinion misleading) of std.algorithm, like
std.algorithm.setDifference accept only SortedRanges?

SetDifference!(less, SortedRange1, SortedRange2) 
setDifference(alias less = "a < b", R1, R2)(SortedRange1 r1, SortedRange2 r2);

The disadvantage is that such functions become a bit more fussy, so you can't
give them normal arrays. The advantage is that if you have to keep around
sorted data, you can perform on it all kinds of elaborations available only
with sorted data and the type system will catch you mistakes like using
unsorted data where sorted is required.

The functions in discussion are:


Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 23 2013