Standard C++ Library Class Reference

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:
There are at least as many elements in the second range as in the first;1.
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
2.
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
//
// equal.cpp
//
#include <algorithm>
#include <vector>
#include <iostream.h>
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;