(C++) std::find\_if
February 24, 2017 · View on GitHub
(C++) std::find_if
STL algorithm for searching an elements in a container, satisfying a certain predicate.
#include <cassert> #include <iterator> #include <vector> int main() { 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"); }