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

[Home]find_if

Synopsis

template<
      typename Sequence
    , typename Pred
    >
struct find_if
{
    typedef unspecified type;
};

Description

Finds the first element in a Sequence that satisfies the predicate Pred.

Definition

#include "boost/mpl/find_if.hpp"

Parameters

 Parameter  Requirement  Description  
SequenceA model of Forward SequenceA sequence to search in.
PredA model of Predicate [Lambda Expression]A search condition.

Expression semantics

 Expression  Expression type  Precondition  Semantics  Postcondition 
typedef find_if<Sequence,Pred>::type i;A model of Forward Iteratori is the first iterator in the range [begin<Sequence>::type, end<Sequence>::type) such that apply< lambda<Pred>::type,i::type >::type::value == true; i is identical to end<Sequence>::type, if no such iterator exists.

Complexity

Linear. At most size<Sequence>::value applications of Pred.

Example

typedef vector<char,int,unsigned,long,unsigned_long> types;
typedef find_if<types, is_same<_1,unsigned> >::type iter;
BOOST_STATIC_ASSERT(iter::pos::value == 2);

See also

Algorithms, find, contains, count, count_if


Table of Contents
Last edited September 15, 2002 7:24 pm