Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

mismatch


Algorithm

Summary

Compares elements from two sequences and returns the first two elements that don't match each other.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#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(InputIterator first1, InputIterator1 last1,
           InputIterator2 first2,
           BinaryPredicate binary_pred);

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:

and i is the first iterator in the range [first1, last1) for which the appropriate one of the following conditions hold:

or

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

Program Output

Warnings

If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you need to write:

vector<int, allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.



Previous fileTop of documentContentsIndexNext file
Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998