Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

mismatch()

Library:  Algorithms


Function

Local Index

No Entries

Summary

Algorithm that compares elements from two sequences and returns a pair of iterators pointing to the first two elements that don't match each other

Synopsis

#include <algorithm>

namespace std {
  template <class InputIterator1, class InputIterator2>
  pair<InputIterator1,InputIterator2>
  mismatch(InputIterator1 start1, InputIterator1 finish1,
           InputIterator2 start2);

  template <class InputIterator1, class InputIterator2,
            class BinaryPredicate>
  pair<InputIterator1, Inputiterator2>
  mismatch(InputIterator1 start1, InputIterator1 finish1,
           InputIterator2 start2,
           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. 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 object. The comparison function object 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 [start1, finish1) 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 finish1 and start2 + (finish1 - start1).

Complexity

At most finish1 - start1 applications of the corresponding predicate are done.

Example

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.1.7



Previous fileTop of DocumentContentsIndex pageNext file