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.isSorted

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

Prototype

bool isSorted(alias less, Range)(
  Range r
)
if (isForwardRange!Range);

Parameters

NameDescription
less Predicate the range should be sorted by.
r Forward range to check for sortedness.

Returns

true if the range is sorted, false otherwise.

Example

int[] arr = [4, 3, 2, 1];
assert(!isSorted(arr));
sort(arr);
assert(isSorted(arr));
sort!("a > b")(arr);
assert(isSorted!("a > b")(arr));

Authors

Andrei Alexandrescu

License

Boost License 1.0.

Comments