count_if

template<class InIt, class Pred, class Dist>
    size_t count_if(InIt first, InIt last,
        Pred pr);

The template function sets a count n to zero. It then executes ++n for each N in the range [0, last - first) for which the predicate pr(*(first + N)) is true. It evaluates the predicate exactly last - first times.

In this implementation, if a translator does not support partial specialization of templates, the return type is size_t instead of iterator_traits<InIt>::distance_type.

See the related sample program.