mismatch function template — Finds first position where two ranges differ
template<typename InIter1, typename InIter2> pair<InIter1, InIter2> mismatch(InIter1 first1, InIter1 last1, InIter2 first2); template<typename InIter1, typename InIter2, typename BinaryPredicate> pair<InIter1, InIter2> mismatch(InIter1 first1, InIter1 last1, InIter2 first2, BinaryPredicate pred);
The mismatch
function
template compares two sequences pairwise and returns a pair of
iterators that identifies the first elements at which the sequences
differ. The first sequence is [first1
, last1
), and the second sequence starts at
first2
and has at least as many
elements as the first sequence.
The return value is a pair of iterators; the first member of
the pair points to an element of the first sequence, and second
member of the pair points to an element of the second sequence. The
two iterators have the same offset within their respective ranges.
If the two sequences are equivalent, the pair returned is last1
and an iterator that points to the
second sequence at the same offset (let's call it last2
).
The first form compares items with the ==
operator. The second form calls
pred(*iter1
, *iter2)
.
Figure 13-8
illustrates how the mismatch
function template works.
The mismatch
function
template returns the pair (first1
+ n
, first2
+ n
), in which n
is the smallest value in [0, last1
- first1
) such that *(first1
+ n
) == *(first2
+ n
) is false and *(first1
+ m
) == *(first2
+ m
) is true for all m
in [0, n
). If there is no such n
, n
= last1
- first1
.
Complexity is linear: at most last1
- first1
comparisons are performed.