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 equal algorithm is similar to mismatch. The Equal algorithm also compares the elements of the two sequences one by one, but the equal function returns the bool value true/false instead of the iterator value. It has the following two prototypes: If the iterator interval [first1, last1) and the iterator interval [first2, first2 + (last1-first1 )) returns true if the element on is equal (or the condition binary_pred meets the condition of binary predicates). Otherwise, false is returned.
Function prototype:
template<class InputIterator1, class InputIterator2> bool equal( InputIterator1 _First1, InputIterator1 _Last1, InputIterator2 _First2 );template<class InputIterator1, class InputIterator2, class BinaryPredicate> bool equal( InputIterator1 _First1, InputIterator1 _Last1, InputIterator2 _First2, BinaryPredicate _Comp );
Example program:
Using Binary predicates to determine the condition absequal, we can determine that the absolute values of elements in two vector containers are equal.
/*************************************** * **************************** Copyright (c) jerry Jiang * file name: equal. CPP * Author: Jerry Jiang * Create Time: 2011-10-10 22:51:07 * mail: jbiaojerry@gmail.com * blog: http://blog.csdn.net/jerryjbiao * Description: simple program interpretation of C ++ STL algorithm series of nine * non variable algorithm: equal element judgment equal ************************************ * ****************************/# include <algorithm> # In Clude <vector> # include <iostream> using namespace STD; bool absequal (int A, int B) {return (A = ABS (B) | B = ABS ())? True: false;} int main () {vector <int> ivect1 (5); vector <int> ivect2 (5); For (vector <int> :: size_type I = 0; I <ivect1.size (); ++ I) {ivect1 [I] = I; ivect2 [I] = (-1) * I ;} if (equal (ivect1.begin (), ivect1.end (), ivect2.begin (), absequal) {cout <"the absolute values of ivect1 and ivect2 are completely equal" <Endl ;} else {cout <"the absolute values of the ivect1 and ivect2 elements are not completely equal" <Endl;} return 0 ;}
**************************************** **************************************** **************************************** *******
C ++ classic bibliography index and resource download:Http://blog.csdn.net/jerryjbiao/article/details/7358796
**************************************** **************************************** **************************************** ********