replaceIf

Performs a linear scan of the complete array, replacing elements where pred returns true.

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

Parameters

array Buffer!(T)

The array to scan.

new_element T

The value to substitute.

pred Pred

The evaluation predicate, which should return true if the element is a valid match and false if not. This predicate may be any callable type.

Return Value

Type: size_t

The number of elements replaced.

Examples

auto buffer = createBuffer("abbc");
test!("==")(replaceIf(buffer, 'x', (char c) { return c > 'a'; }), 3);
test!("==")(buffer[], "axxx");
auto array = "abbc".dup;
test!("==")(replaceIf(array, 'x', (char c) { return c > 'a'; }), 3);
test!("==")(array, "axxx");

Meta