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 an old version of boost. Click here for the latest version's documentation home page.

[Home]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  
SequenceA model of Forward SequenceA sequence to be examined.
PredA 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 ConstantEquivalent 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