partition

Partitions array such that all elements that satisfy pred will be placed before the elements that do not satisfy pred. The algorithm is not required to be stable.

  1. size_t partition(T[] array, Pred pred)
    size_t
    partition
    (
    T
    Pred
    )
    (
    T[] array
    ,
    Pred pred
    )
  2. size_t partition(Buffer!(T) array, Pred pred)

Parameters

array T[]

The array to partition. This parameter is not marked 'ref' to allow temporary slices to be sorted. As array is not resized in any way, omitting the 'ref' qualifier has no effect on the result of this operation, even though it may be viewed as a side-effect.

pred Pred

The evaluation predicate, which should return true if the element satisfies the condition and false if not. This predicate may be any callable type.

Return Value

Type: size_t

The number of elements that satisfy pred.

Examples

auto array = "af242df56s2".dup;
test!("==")(partition(array, (char c) { return c >= '0' && c <= '9'; }), 6);
auto buffer = createBuffer("af242df56s2");
test!("==")(partition(buffer, (char c) { return c >= '0' && c <= '9'; }), 6);

Meta