filterInPlace

Moves all elements from array which match the exclusion criterum represented by exclude to the back of array so that the elements that do not match this criterium are in the front.

array is modified in-place, the order of the elements may change.

exclude is expected to be callable (function or delegate), accepting exactly one T argument and returning an integer (bool, (u)int, (u)short or (u)long). It is called with the element in question and should return true if that element should moved to the back or false if to the front.

size_t
filterInPlace
(
T
Exclude
)
(
T[] array
,
Exclude exclude
)
out (end) { assert (end <= array.length, "result index out of bounds"); }

Parameters

array T[]

array to move values matching the exclusion criterum to the back

exclude Exclude

returns true if the element matches the exclusion criterium

Return Value

Type: size_t

the index of the first excluded elements in array. This element and all following ones matched the exclusion criterum; all elements before it did not match. 0 indicates that all elements matched the exclusion criterium and array.length that none matched.

This allows the calling code to keep only the non-excluded items by calling: arr.length = filterInPlace(arr, filterFunc);

Out: The returned index is at most array.length.

Meta