Would it be an acceptable enhancement to phobos to expose the predicate in SortedRange (https://dlang.org/library/std/range/sorted_range.html)?

The rationale behind it would be so that functions like setDifference (https://dlang.org/library/std/algorithm/setops/set_difference.html) or any function that requires a sorted range to "run" does not need to be provided the sorting predicate, ie:

setDifference
largestPartialIntersection
largestPartialIntersectionWeighted
multiwayUnion
setIntersection
setSymmetricDifference
setUnion
multiwayMerge

Where functions do required ranges to be sorted and a predicate passed in, this enhancement should reduce programmer errors (i.e. providing the wrong predicate to the algorithm that was used to sort the range that you want to operate on). The sortedrange knows how it was sorted, so there should be no need to duplicate that (unless there are maybe some valid reasons?).

It would also make for SortedRange itself to be made lighter (maybe not a good idea at this point but it can be done at least) by moving it's functionality in to algorithms that are already there. Eg, "SortedRange.contains" can be done by algorithm.canFind:

auto canFind(Range, T)(Range range, T element) if (isSortedRange!Range) {
  // do binary search for element
}

PS: Is this the correct place for posts like this? Apologies if not :s

Reply via email to