View source code
Display the source code in std/algorithm/sorting.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.algorithm.sorting.strictlyOrdered
Like , returns isSortedtrue if the given are valuesordered
according to the comparison operation less. Unlike , takes isSortedvalues
directly instead of structured in a range.
allows repeated orderedvalues, e.g. is ordered(1, 1, 2)true. To verify
that the values are ordered strictly monotonically, use ;
strictlyOrdered is strictlyOrdered(1, 1, 2)false.
With either function, the predicate must be a strict ordering just like with . For
example, using isSorted"a <= b" instead of "a < b" is incorrect and will cause failed
assertions.
Prototype
bool strictlyOrdered(alias less, T...)( T values ) if (is(typeof(ordered!less(values))));
Parameters
| Name | Description |
|---|---|
| values | The tested value |
| less | The comparison predicate |
Returns
true if the values are ordered; allows for duplicates,
ordered does not.
strictlyOrdered
Example
assert(ordered(42, 42, 43)); assert(!strictlyOrdered(43, 42, 45)); assert(ordered(42, 42, 43)); assert(!strictlyOrdered(42, 42, 43)); assert(!ordered(43, 42, 45)); // Ordered lexicographically assert(ordered("Jane", "Jim", "Joe")); assert(strictlyOrdered("Jane", "Jim", "Joe")); // Incidentally also ordered by length decreasing assert(ordered!((a, b) => a.length > b.length)("Jane", "Jim", "Joe")); // ... but not strictly so: "Jim" and "Joe" have the same length assert(!strictlyOrdered!((a, b) => a.length > b.length)("Jane", "Jim", "Joe"));