The OpenD Programming Language

assumeSorted

Assumes r is sorted by predicate pred and returns the corresponding SortedRange!(pred, R) having r as support. To check for sorted-ness at cost O(n), use std.algorithm.sorting.isSorted.

assumeSorted
(
alias pred = "a < b"
R
)
(
R r
)

Examples

import std.algorithm.comparison : equal;

int[] a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
auto p = assumeSorted(a);

assert(equal(p.lowerBound(4), [0, 1, 2, 3]));
assert(equal(p.lowerBound(5), [0, 1, 2, 3, 4]));
assert(equal(p.lowerBound(6), [0, 1, 2, 3, 4, 5]));
assert(equal(p.lowerBound(6.9), [0, 1, 2, 3, 4, 5, 6]));

Meta