std.algorithm

This package implements generic algorithms oriented towards the processing of sequences. Sequences processed by these functions define range-based interfaces. 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 a compile-time string. The string may consist of any legal D expression that uses the symbol a (for unary functions) or the symbols a and b (for binary functions). These names will NOT interfere with other homonym symbols in user code because they are evaluated in a different context. The default for all binary comparison predicates is "a == b" for unordered operations and "a < b" for ordered operations.

Modules

comparison
module std.algorithm.comparison

This is a submodule of std.algorithm. It contains generic comparison algorithms.

iteration
module std.algorithm.iteration

This is a submodule of std.algorithm. It contains generic iteration algorithms.

mutation
module std.algorithm.mutation

This is a submodule of std.algorithm. It contains generic mutation algorithms.

searching
module std.algorithm.searching

This is a submodule of std.algorithm. It contains generic searching algorithms.

setops
module std.algorithm.setops

This is a submodule of std.algorithm. It contains generic algorithms that implement set operations.

sorting
module std.algorithm.sorting

This is a submodule of std.algorithm. It contains generic sorting algorithms.

Public Imports

std.algorithm.comparison
public import std.algorithm.comparison;
Undocumented in source.
std.algorithm.iteration
public import std.algorithm.iteration;
Undocumented in source.
std.algorithm.mutation
public import std.algorithm.mutation;
Undocumented in source.
std.algorithm.searching
public import std.algorithm.searching;
Undocumented in source.
std.algorithm.setops
public import std.algorithm.setops;
Undocumented in source.
std.algorithm.sorting
public import std.algorithm.sorting;
Undocumented in source.

Examples

int[] a = ...;
static bool greater(int a, int b)
{
    return a > b;
}
sort!greater(a);           // predicate as alias
sort!((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

Meta