The OpenD Programming Language

isStrictlyMonotonic

Checks whether a forward range is sorted according to the comparison operation less. Performs O(r.length) evaluations of less.

Unlike isSorted, isStrictlyMonotonic does not allow for equal values, i.e. values for which both less(a, b) and less(b, a) are false.

With either function, the predicate must be a strict ordering just like with isSorted. For example, using "a <= b" instead of "a < b" is incorrect and will cause failed assertions.

bool
isStrictlyMonotonic
(
alias less = "a < b"
Range
)
(
Range r
)

Parameters

less

Predicate the range should be sorted by.

r Range

Forward range to check for sortedness.

Return Value

Type: bool

true if the range is sorted, false otherwise. isSorted allows duplicates, isStrictlyMonotonic not.

Examples

assert([1, 1, 2].isSorted);
// strictly monotonic doesn't allow duplicates
assert(![1, 1, 2].isStrictlyMonotonic);

int[] arr = [4, 3, 2, 1];
assert(!isSorted(arr));
assert(!isStrictlyMonotonic(arr));

assert(isSorted!"a > b"(arr));
assert(isStrictlyMonotonic!"a > b"(arr));

sort(arr);
assert(isSorted(arr));
assert(isStrictlyMonotonic(arr));

Meta