removeIf

Performs a linear scan of complete array, removing all elements that satisfy pred from the sequence. The relative order of elements that do not satisfy pred will be preserved.

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

Parameters

array Buffer!(T)

The array to scan. This parameter is not marked 'ref' to allow temporary slices to be modified. 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 do not satisfy pred.

Examples

auto buffer = createBuffer("abbcc");
test!("==")(removeIf(buffer, (char c) { return c == 'b'; }), 3);
test!("==")(buffer[], "accbb");
auto array = "abbcc".dup;
test!("==")(removeIf(array, (char c) { return c == 'b'; }), 3);
test!("==")(array, "accbb");

Meta