count_if
template<
typename Sequence
, typename Pred
>
struct count_if
{
typedef unspecified type;
};
Returns the number of elements in a Sequence that satisfy the predicate Pred.
#include "boost/mpl/count_if.hpp"
| Parameter | Requirement | Description |
|---|---|---|
Sequence | A model of Forward Sequence | A sequence to be examined. |
Pred | A model of Predicate [Lambda Expression] | The count condition. |
| Expression | Expression type | Precondition | Semantics | Postcondition |
|---|---|---|---|---|
typedef count_if<Sequence,Pred>::type n; | A model of Integral Constant | Equivalent to typedef lambda<Pred>::type pred; typedef fold< Sequence,integral_c<unsigned long,0>,if_<pred,next<_1>,_1> >::type n; |
Linear. Exactly size<Sequence>::value applications of Pred.
typedef list<int,char,long,short,char,long,double,long> types;BOOST_STATIC_ASSERT((count_if< types,boost::is_float<_> >::type::value == 1)); BOOST_STATIC_ASSERT((count_if< types,boost::is_same<_,char> >::type::value == 2)); BOOST_STATIC_ASSERT((count_if< types,boost::is_same<_,void> >::type::value == 0));
Algorithms, count, find_if, find, contains