.\" ident @(#)equal.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH equal 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2equal\fP \ - Compares two ranges for equality. .SH SYNOPSIS .br #include .br .br template .br bool equal(InputIterator1 first1, InputIterator1 last1, .RE .RS 11 InputIterator2 first2); .RE .RS 0 .br template .RE .RS 0 bool equal(InputIterator1 first1, InputIterator1 last1, .RE .RS 11 InputIterator2 first2, BinaryPredicate .br binary_pred); .SH 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 \f2true\fP if all of the corresponding elements are equal to each other. The second version of equal returns \f2true\fP if for each pair of elements in the two ranges, the result of applying the binary predicate is \f2true\fP. In other words, equal returns \f2true\fP if both of the following are \f2true\fP: .HP .5i 1. There are at least as many elements in the second range as in the first; .HP .5i 2. For every iterator \f2i\fP in the range \f2[first1, last1)\fP the following corresponding conditions hold: .HP .5i \f2*i == *(first2 + (i - first1))\fP .HP .5i or .HP .5i \f2binary_pred(*i, *(first2 + (i - first1))) == true\fP .HP 0 Otherwise, equal returns \f2false\fP. This algorithm assumes that there are at least as many elements available after \f2first2\fP as there are in the range \f2[first1, last1).\fP .SH COMPLEXITY equal performs at most \f2last1-first1\fP comparisons or applications of the predicate. .SH EXAMPLE .RE .RS 0 // .br // equal.cpp .br // .RE .RS 1 #include .br #include .br #include .br #include .RE .RS 0 using namespace std; .br .br int main() .RE .RS 1 { .RE .RS 2 int d1[4] = {1,2,3,4}; .br int d2[4] = {1,2,4,3}; .RE .RS 3 // .br // Set up two vectors .br // .RE .RS 2 vector v1(d1+0, d1 + 4), v2(d2+0, d2 + 4); .RE .RS 0 .RE .RS 3 // Check for equality .RE .RS 2 bool b1 = equal(v1.begin(),v1.end(),v2.begin()); .br bool b2 = equal(v1.begin(),v1.end(), .RE .RS 18 v2.begin(),equal_to()); .RE .RS 0 .RE .RS 3 // Both b1 and b2 are false .RE .RS 2 cout << (b1 ? "TRUE" : "FALSE") << " " .RE .RS 8 << (b2 ? "TRUE" : "FALSE") << endl; .RE .RS 2 return 0; .RE .RS 1 } .br .RE .RS 0 Program Output .RE .RS 0 .br FALSE FALSE .SH WARNINGS If your compiler does not support default template parameters, then you always need to supply the \f2Allocator\fP template argument. For instance, you have to write: \f2vector >\fP instead of: \f2vector\fP If your compiler does not support namespaces, then you do not need the using declaration for \f2std\fP.