...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.45. Parameters
Parameter |
Requirement |
Description |
---|---|---|
seq |
A model of Forward Sequence, f(e) is a valid expression, convertible to bool, for each element e in seq |
The sequence to search |
f |
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 result_of::size<Sequence>::value comparisons.
#include <boost/fusion/algorithm/query/count_if.hpp> #include <boost/fusion/include/count_if.hpp>
const vector<int,int,int> vec(1,2,3); assert(count_if(vec,odd()) == 2);