Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

equal


Algorithm

Summary

Compares two ranges for equality.

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

None

Synopsis

#include <algorithm>

template <class InputIterator1, class InputIterator2>
 bool equal(InputIterator1 first1, InputIterator1 last1,
            InputIterator2 first2);

template <class InputIterator1, class InputIterator2,
          class BinaryPredicate>
 bool equal(InputIterator1 first1, InputIterator1 last1,
            InputIterator2 first2, BinaryPredicate
            binary_pred);

Description

The equal algorithm does a pairwise comparison of all of the elements in one range with all of the elements in another range to see if they match. The first version of equal uses the equal operator (==) as the comparison function, and the second version allows you to specify a binary predicate as the comparison function. The first version returns true if all of the corresponding elements are equal to each other. The second version of equal returns true if for each pair of elements in the two ranges, the result of applying the binary predicate is true. In other words, equal returns true if both of the following are true:

  1. There are at least as many elements in the second range as in the first;

  2. For every iterator i in the range [first1, last1) the following corresponding conditions hold:

  3. *i == *(first2 + (i - first1))

    or

    binary_pred(*i, *(first2 + (i - first1))) == true

Otherwise, equal returns false.

This algorithm assumes that there are at least as many elements available after first2 as there are in the range [first1, last1).

Complexity

equal performs at most last1-first1 comparisons or applications of the predicate.

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 have 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 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998