Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
count
Description

Returns the number of elements of a given type within a sequence.

Synopsis
template<
    typename Sequence,
    typename T
    >
typename result_of::count<Sequence, T>::type count(
    Sequence const& seq, T const& t);

Table 1.57. Parameters

Parameter

Requirement

Description

seq

A model of Forward Sequence, e == t must be a valid expression, convertible to bool, for each element e in seq

The sequence to search

T

Any type

The type to count


Expression Semantics
count(seq, t);

Return type: int

Semantics: Returns the number of elements of type T and equal to t in seq.

Complexity

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

Header
#include <boost/fusion/algorithm/query/count.hpp>
#include <boost/fusion/include/count.hpp>
Example
const vector<double,int,int> vec(1.0,2,3);
assert(count(vec,2) == 1);

PrevUpHomeNext