Standard C++ Library Class Reference
Description
The mismatch algorithm compares members of two sequences and returns two iterators (i and j)
that point to the first location in each sequence where the sequences differ from each other.
Notice that the algorithm denotes both a starting position and an ending position for the first
sequence, but denotes only a starting position for the second sequence. mismatch assumes that
the second sequence has at least as many members as the first sequence. If the two sequences are
identical, mismatch returns a pair of iterators that point to the end of the first sequence and the
corresponding location at which the comparison stopped in the second sequence.
The first version of mismatch checks members of a sequence for equality, while the second
version lets you specify a comparison function. The comparison function must be a binary
predicate.
The iterators i and j returned by mismatch are defined as follows:
j == first2 + (i - first1)
and i is the first iterator in the range [first1, last1) for which the appropriate one of the following
conditions hold:
!(*i == *(first2 + (i - first1)))
or
binary_pred(*i, *(first2 + (i - first1))) == false
If all of the members in the two sequences match, mismatch returns a pair of last1 and first2 +
(last1 - first1).
Complexity
At most last1 - first1 applications of the corresponding predicate are done.
Example
//
// mismatch.cpp
//
#include <algorithm>
#include <vector>
#include <iostream.h>
int main(void)
{
typedef vector<int>::iterator iterator;
int d1[4] = {1,2,3,4};
int d2[4] = {1,3,2,4};
// Set up two vectors
vector<int> vi1(d1,d1 + 4), vi2(d2,d2 + 4);