.. _sprout-algorithm-count_if: ############################################################################### count_if ############################################################################### Interface ======================================== .. sourcecode:: c++ template inline SPROUT_CONSTEXPR typename std::iterator_traits::difference_type count_if(InputIterator first, InputIterator last, Predicate pred); Returns ======================================== | The number of iterators i in the range [first,last) for which the following corresponding conditions hold: ``pred(*i)``. Examples ======================================== .. sourcecode:: c++ #include #include #include #include using namespace sprout; SPROUT_STATIC_CONSTEXPR auto input = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; SPROUT_STATIC_CONSTEXPR auto result = sprout::count_if(begin(input), end(input), bind2nd(modulus<>(), 2)); static_assert(result == 5, "counted 5 elements of odd number from input."); Complexity ======================================== | Exactly ``last - first`` applications of the predicate. | Recursive function invocations in *O(logN)* (logarithmic) depth. Header ======================================== | ``sprout/algorithm/count_if.hpp`` | Convenience header: ``sprout/algorithm.hpp``