| Home | Libraries | People | FAQ | More

##### count_if

###### Description

Returns the number of elements within a sequence with a type for which a given unary function object evaluates to `true`.

###### Synopsis

    template<
        typename Sequence,
        typename F
        >
    typename result_of::count_if<Sequence, F>::type count_if(
        Sequence const& seq, F f);

Table 1.56. 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

###### Expression Semantics

    count_if(seq, f)

Return type: `int`

Semantics: Returns the number of elements in `seq` where `f` evaluates to `true`.

###### Complexity

Linear. At most ``result_of::size`<Sequence>::value` comparisons.

###### Header

    #include <boost/fusion/algorithm/query/count_if.hpp>
    #include <boost/fusion/include/count_if.hpp>

###### Example

    const vector<int,int,int> vec(1,2,3);
    assert(count_if(vec,odd()) == 2);