countUntil

fnauto countUntil(alias pred = "a == b", R, Rs...)(R haystack, Rs needles) if (isForwardRange!R && Rs.length > 0 && isForwardRange!(Rs[0]) == isInputRange!(Rs[0]) && allSatisfy!(canTestStartsWith!(pred, R), Rs))

Counts elements in the given

input range

until the given predicate is true for one of the given needles or needle.

Parameters

predBinary predicate for determining when to stop counting, which will be passed each element of haystack and a needle.
haystackThe input range to be counted. Must be a forward range to use multiple needles.
needlesA sequence of values or forward ranges of values, to be evaluated in turn by calling pred(element, needle) with each element of haystack.
needleA value passed as the 2nd argument to pred.

Returns

- The number of elements which must be popped from the front of

haystack before reaching an element for which

startsWith!pred(haystack, needles) is true.
  • If

startsWith!pred(haystack, needles) is not true for any element in haystack, then -1 is returned.

  • If more than one needle is provided,

countUntil will wrap the result in a pseudo-tuple similar to Tuple!(ptrdiff_t, "steps", ptrdiff_t, "needle").

  • steps is the count value, which can be implicitly tested for equality.
  • needle is the index into needles which matched.
  • Both are -1 if there was no match.

Warning: Due to auto-decoding, the return value of this function may not correspond to the array index for strings. To find the index of an element matching the predicate in a string, use indexOf instead.

See Also

fnptrdiff_t countUntil(alias pred = "a == b", R, N)(R haystack, N needle) if (isInputRange!R && is(typeof(binaryFun!pred(haystack.front, needle)) : bool))

ditto

fnptrdiff_t countUntil(alias pred, R)(R haystack) if (isInputRange!R && is(typeof(unaryFun!pred(haystack.front)) : bool))

Counts elements in the given

input range

until the given predicate is true for one of the elements of haystack.

Parameters

predUnary predicate for determining when to stop counting.
haystackThe input range to be counted.

Returns

- 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.

Warning: Due to auto-decoding, the return value of this function may not correspond to the array index for strings. To find the index of an element matching the predicate in a string, use indexOf instead.