count will not accept
infinite ranges for haystack.
Parameters
pred | The predicate to compare elements. |
haystack | The range to _count. |
needle | The element or sub-range to _count in haystack. |
Returns
haystack.size_t count(alias pred = "a == b", Range, E)(Range haystack, E needle) if (isInputRange!Range && !isInfinite!Range &&
is(typeof(binaryFun!pred(haystack.front, needle))))Counts matches of needle in haystack.
The first overload counts each element e in haystack for which pred(e, needle) is true. pred defaults to equality. Performs haystack.length evaluations of pred.
The second overload counts the number of times needle was matched in haystack. pred compares elements in each range. Throws an exception if needle.empty is true, as the _count of the empty range in any range would be infinite. Overlapped counts are not considered, for example count("aaa", "aa") is 1, not 2.
count will not accept
infinite ranges for haystack.
pred | The predicate to compare elements. |
haystack | The range to _count. |
needle | The element or sub-range to _count in haystack. |
haystack.size_t count(alias pred = "a == b", R1, R2)(R1 haystack, R2 needle) if (isForwardRange!R1 && !isInfinite!R1 &&
isForwardRange!R2 &&
is(typeof(binaryFun!pred(haystack.front, needle.front))))Ditto
size_t count(alias pred, R)(R haystack) if (isInputRange!R && !isInfinite!R &&
is(typeof(unaryFun!pred(haystack.front))))Counts all elements or elements satisfying a predicate in haystack.
The first overload counts each element e in haystack for which pred(e) is true. Performs haystack.length evaluations of pred.
The second overload counts the number of elements in a range. If the given range has the length property, that is returned right away, otherwise performs haystack.length to walk the range.
pred | Optional predicate to find elements. |
haystack | The range to _count. |
haystack (for which pred returned true).