C ++ STL's non-mutating algorithms is a set of template functions that do not destroy operation data, it is used for processing sequence data one by one, element search, subsequence search, statistics, and matching.
The find_if algorithm is a predicate version of the find algorithm. It uses the predicates that return boolean values to determine the PRED and checks every element in the iterator range [first, last, if the iterator ITER satisfies PRED (* ITER) = true, the element is found and the iterator value ITER is returned. If no element is found, the last is returned.
Function prototype:
template<class InputIterator, class Predicate> InputIterator find_if( InputIterator _First, InputIterator _Last, Predicate _Pred );
Sample Code:
/*************************************** * **************************** Copyright (c) jerry Jiang * file name: find_if.cpp * Author: Jerry Jiang * Create Time: 2011-9-29 22:21:29 * mail: jbiaojerry@gmail.com * blog: http://blog.csdn.net/jerryjbiao * description: simple programs interpret C ++ STL algorithm series 3 * Non-Variable Algorithms: conditional search for the container element find_if *********************************** * *****************************/# include <Algorithm> # Include <vector> # include <iostream> using namespace STD; // predicate judgment function divbyfive: determines whether X can divide bool divbyfive (int x) {return X % 5? 0: 1;} int main () {// initial vectorvector <int> ivect (20); For (size_t I = 0; I <ivect. size (); ++ I) {ivect [I] = (I + 1) * (I + 3) ;}vector <int >:: iterator ilocation; ilocation = find_if (ivect. begin (), ivect. end (), divbyfive); If (ilocation! = Ivect. end () {cout <"the first element to be divisible by 5 is:" <* ilocation <Endl // print element: 15 <"the index position of the element is:" <ilocation-ivect. begin () <Endl; // print index location: 2} return 0 ;}
**************************************** **************************************** **************************************** *******
C ++ classic bibliography index and resource download:Http://blog.csdn.net/jerryjbiao/article/details/7358796
**************************************** **************************************** **************************************** ********