View source code
Display the source code in std/meta.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

Enum member std.meta.staticIsSorted

Checks if an AliasSeq is sorted according to cmp.

enum staticIsSorted(alias cmp, items...) = () { static if (items.length > 1) { static foreach (i, item; items[1..__dollar]) { static if (!isLessEq!(cmp, items[i], item)) { if (__ctfe) return false; } } } return true; } ();

Parameters

cmp = A template that returns a bool (if its first argument is less than the second one) or an int (-1 means less than, 0 means equal, 1 means greater than)

Seq = The AliasSeq to check

Returns

true if Seq is sorted; otherwise false

Example

enum Comp(int N1, int N2) = N1 < N2;
static assert( staticIsSorted!(Comp, 2, 2));
static assert( staticIsSorted!(Comp, 2, 3, 7, 23));
static assert(!staticIsSorted!(Comp, 7, 2, 3, 23));

Example

enum Comp(T1, T2) = __traits(isUnsigned, T2) - __traits(isUnsigned, T1);
static assert( staticIsSorted!(Comp, uint, ubyte, ulong, short, long));
static assert(!staticIsSorted!(Comp, uint, short, ubyte, long, ulong));

Authors

Walter Bright, David Nadlinger

License

Boost License 1.0.