Standard C++ Library
Copyright 1998, Rogue Wave Software, Inc.

## NAME

__equal__
- Compares two ranges for equality.

## 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:
*__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 ele-
ments available after __first2__ as there are in the range
[__first1__, __last1__).

## COMPLEXITY

equal performs at most __last1__-__first1__ comparisons or applica-
tions of the predicate.

## EXAMPLE

//
// equal.cpp
//
#include <algorithm>
#include <vector>
#include <functional>
#include <iostream>
using namespace std;
int main()
{
int d1[4] = {1,2,3,4};
int d2[4] = {1,2,4,3};
//
// Set up two vectors
//
vector<int> v1(d1+0, d1 + 4), v2(d2+0, d2 + 4);
// Check for equality
bool b1 = equal(v1.begin(),v1.end(),v2.begin());
bool b2 = equal(v1.begin(),v1.end(),
v2.begin(),equal_to<int>());
// Both b1 and b2 are false
cout << (b1 ? "TRUE" : "FALSE") << " "
<< (b2 ? "TRUE" : "FALSE") << endl;
return 0;
}
Program Output
FALSE FALSE

## WARNINGS

If your compiler does not support default template parame-
ters, 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__.