Syntax:
#include <algorithm> bool equal( input_iterator start1, input_iterator end1, input_iterator2 start2 ); bool equal( input_iterator start1, input_iterator end1, input_iterator2 start2, BinPred p );
The equal
function returns true if the elements in two ranges are the same.
The first range of elements are those between start1
and end1
. The second range
of elements has the same size as the first range but starts at start2
.
If the binary predicate p
is specified, then it is used instead of == to
compare each pair of elements.
For example, the following code uses equal
to compare two vectors of
integers:
vector<int> v1; for( int i = 0; i < 10; i++ ) { v1.push_back( i ); } vector<int> v2; for( int i = 0; i < 10; i++ ) { v2.push_back( i ); } if( equal( v1.begin(), v1.end(), v2.begin() ) ) { cout << "v1 and v2 are equal" << endl; } else { cout << "v1 and v2 are NOT equal" << endl; }
Related Topics: find_if, lexicographical_compare, mismatch, search