Or login with:
#include <algorithm> template < class InputIterator1, class InputIterator2 > pair < InputIterator1, InputIterator2 > mismatch( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 ); template < class InputIterator1, class InputIterator2, class BinaryPredicate > pair < InputIterator1, InputIterator2 > mismatch( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 BinaryPredicate comp );Parameters:
| Parameter | Description |
|---|---|
| first1 | An input iterator addressing the position of the first element in the first range to be tested |
| last1 | An input iterator addressing the position one past the final element in the first range to be tested |
| first2 | An input iterator addressing the position of the first element in the second range to be tested |
| comp | User-defined predicate function object that defines the condition to be satisfied if two elements are to be taken as equivalent. A binary predicate takes two arguments and returns true when satisfied and false when not satisfied |
[first1,last1) and the range beginning at first2 for the first pair of mismatched (unequal) values.
The second version of mismatch finds the first iterator i in [first1, last1) such that binary_pred (*i, *(first2 + (i - first1)) is false.last1 - first1 comparisons.#include <iostream> #include <vector> #include <algorithm> #include <utility> using namespace std; int main() { vector<int> coll1; list<int> coll2; INSERT_ELEMENTS(coll1,1,6); for (int i=1; i<=16; i*=2) { col12.push_back(i); } coll2.push_back(3); PRINT_ELEMENTS(coll1,"coll1: "); PRINT_ELEMENTS(coll2,"coll2: "); //find first mismatch pair<vector<int>::iterator,list<int>::iterator> values; values = mismatch (coll1.begin(), coll1.end(), //first range coll2.begin()); //second range if (values.first == coll1.end()) cout <<"no mismatch"<<endl; else cout <<"first mismatch: "<<*values.first<<" and "<<*values.second<<endl; /*find first position where the element of coll1 is not *less than the corresponding element of coll2 */ values = mismatch (coll1.begin(), coll1.end(), //first range col12. begin(), //second range less_equal<int>() ) //criterion if (values.first == coll1.end()) cout <<"always less-or-equal"<<endl; else cout <<"not less-or-equal: "<<*values.first<<" and " <<*values.second<<endl; return 0; }
You must login to leave a messge