The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
Visual Studio 2012
Locates the position of the first occurrence of an element in a range that satisfies a specified condition.
template<class InputIterator, class Predicate>
InputIterator find_if(
InputIterator _First,
InputIterator _Last,
Predicate _Pred
);
This template function is a generalization of the algorithm find, replacing the predicate "equals a specific value" with any predicate.
// alg_find_if.cpp
// compile with: /EHsc
#include <list>
#include <algorithm>
#include <iostream>
bool greater10 ( int value )
{
return value >10;
}
int main( )
{
using namespace std;
list <int> L;
list <int>::iterator Iter;
list <int>::iterator result;
L.push_back( 5 );
L.push_back( 10 );
L.push_back( 15 );
L.push_back( 20 );
L.push_back( 10 );
cout << "L = ( " ;
for ( Iter = L.begin( ) ; Iter != L.end( ) ; Iter++ )
cout << *Iter << " ";
cout << ")" << endl;
result = find_if( L.begin( ), L.end( ), &greater10 );
if ( result == L.end( ) )
cout << "There is no element greater than 10 in list L."
<< endl;
else
{
result++;
cout << "There is an element greater than 10 in list L,"
<< "\n and it is followed by a "
<< *(result) << "." << endl;
}
}
L = ( 5 10 15 20 10 ) There is an element greater than 10 in list L, and it is followed by a 20.