Example
bool ascending(int a, int b) { return a > b; } bool descending(int a, int b) { return a < b; } template Ascending(int a, int b) { enum Ascending = a > b; } template Descending(int a, int b) { enum Descending = a < b; } static assert([staticSort!(ascending, 3, 1, 5, 2)] == [1, 2, 3, 5]); static assert([staticSort!(Ascending, 3, 1, 5, 2)] == [1, 2, 3, 5]); static assert([staticSort!(descending, 3, 1, 5, 2)] == [5, 3, 2, 1]); static assert([staticSort!(Descending, 3, 1, 5, 2)] == [5, 3, 2, 1]); import std.string; bool wordsCmp(string a, string b) { return toUpper(a) > toUpper(b); } alias words = ExpressionList!("aBc", "a", "abc", "b", "ABC", "c"); alias sortedWords = staticSort!(wordsCmp, words); static assert([sortedWords] == [ "a", "aBc", "abc", "ABC", "b", "c" ]);
Perfoms merge sort algorithm on expression list T using function/template F that takes two elements and returns boolean.