Boost C++ Libraries 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 for the latest Boost documentation.



      typename Sequence
    , typename Pred
struct count_if
    typedef unspecified type;


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


#include "boost/mpl/count_if.hpp"


 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;


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


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