countUntil

Counts elements in the given input range until the given predicate is true for one of the elements of haystack.

  1. auto countUntil(R haystack, Rs needles)
  2. ptrdiff_t countUntil(R haystack, N needle)
  3. ptrdiff_t countUntil(R haystack)
    ptrdiff_t
    countUntil
    (
    alias pred
    R
    )
    if (
    is(typeof(unaryFun!pred(haystack.front)) : bool)
    )

Parameters

pred

Unary predicate for determining when to stop counting.

haystack R

The input range to be counted.

Return Value

Type: ptrdiff_t

- The number of elements which must be popped from the front of haystack before reaching an element for which startsWith!pred(haystack) is true. - If startsWith!pred(haystack) is not true for any element in haystack, then -1 is returned.

Examples

import std.ascii : isDigit;
import std.uni : isWhite;

assert(countUntil!(isWhite)("hello world") == 5);
assert(countUntil!(isDigit)("hello world") == -1);
assert(countUntil!"a > 20"([0, 7, 12, 22, 9]) == 3);

Meta