boost::mpl::count_if

# count_if

### Synopsis

    template<
          typename Sequence
        , typename Pred
        >
    struct count_if
    {
        typedef unspecified type;
    };

### Description

Returns the number of elements in a `Sequence` that satisfy the predicate `Pred`.

### Definition

    #include "boost/mpl/count_if.hpp"

### Parameters

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 semantics

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;` |

### Complexity

Linear. Exactly `size<Sequence>::value` applications of `Pred`.

### Example

    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));

### See also

Algorithms, `count`, `find_if`, `find`, `contains`

Table of Contents
Last edited July 17, 2002 4:32 am