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 a snapshot of the develop branch, built from commit 4e5b2d57df.
Front Page / Algorithms / Querying Algorithms / count

count

Synopsis

template<
      typename Sequence
    , typename T
    >
struct count
{
    typedef unspecified type;
};

Description

Returns the number of elements in a Sequence that are identical to T.

Header

#include <boost/mpl/count.hpp>

Parameters

Parameter Requirement Description
Sequence Forward Sequence A sequence to be examined.
T Any type A type to search for.

Expression semantics

For any Forward Sequence s and arbitrary type t:

typedef count<s,t>::type n;
Return type:

Integral Constant.

Semantics:

Equivalent to

typedef count_if< s,is_same<_,T> >::type n;

Complexity

Linear. Exactly size<s>::value comparisons for identity.

Example

typedef vector<int,char,long,short,char,short,double,long> types;
typedef count<types, short>::type n;

BOOST_MPL_ASSERT_RELATION( n::value, ==, 2 );

See also

Querying Algorithms, count_if, find, find_if, contains, lower_bound