Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
STL algorithm for searching an elements in a container, satisfying a certain predicate.
{
typedef std::vector<int>::const_iterator Iterator;
std::vector<int> v;
v.push_back(-2);
v.push_back(-1);
v.push_back( 0);
v.push_back( 1);
v.push_back( 2);
//Find the first element in v that has an integer value bigger then zero
const Iterator result
= std::find_if(v.begin(), v.end(),
std::bind2nd(std::greater<int>(), 0));
assert(result == v.end() && "A result is found");
assert(*result > 0 && "The result found is valid");
}
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.