...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Returns the number of elements within a sequence with a type for which
a given unary function object evaluates to true
.
template<
typename Sequence,
typename F
>
typename result_of::count_if
<Sequence, F>::type count_if(
Sequence const& seq, F f);
Table 1.58. Parameters
Parameter |
Requirement |
Description |
---|---|---|
|
A model of Forward
Sequence, |
The sequence to search |
|
A unary function object |
The search predicate |
count_if
(seq, f)
Return type: int
Semantics: Returns the number of elements
in seq
where f
evaluates to true
.
Linear. At most
comparisons.
result_of::size
<Sequence>::value
#include <boost/fusion/algorithm/query/count_if.hpp> #include <boost/fusion/include/count_if.hpp>
constvector
<int,int,int> vec(1,2,3); assert(count_if
(vec,odd()) == 2);