Report a bugIf you spot a problem with this page, click here to create a Bugzilla issue.
Improve this pageQuickly 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 usinga local clone.
std.algorithm
This package implements generic algorithms oriented towards the processing ofsequences. Sequences processed by these functions define range-basedinterfaces. See also
Reference on ranges and
tutorial on ranges.
Algorithms are categorized into the following submodules:
Many functions in this package are parameterized with a
predicate.The predicate may be any suitable callable type(a function, a delegate, a
functor, or a lambda), or acompile-time string. The string may consist of
any legal Dexpression that uses the symbol
a (for unary functions) or thesymbols
a and
b (for binary functions). These names will NOTinterfere with other homonym symbols in user code because they areevaluated in a different context. The default for all binarycomparison predicates is
"a == b" for unordered operations and
"a < b" for ordered operations.
Example
int[] a = ...;staticbool greater(int a,int b){return a > b;}sort!greater(a);// predicate as aliassort!((a, b) => a > b)(a);// predicate as a lambda.sort!"a > b"(a);// predicate as string// (no ambiguity with array name)sort(a);// no predicate, "a < b" is implicit