Declaration
template <class InputIterator1, class InputIterator2> inline 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 Each equal function returns true (i.e., a non-zero value) if the range [ first1, last1) and the range of size n beginning at first2 , where n is the size of the range [ first1, last1) , contain the same elements in the same order , false (i.e., 0) otherwise. In the first function checks for element equality are made with operator==, while in the second they are made with the function object binary_pred.
Type requirements
Group Non-mutating sequence operations.
Time complexity Linear.
If the two sequences are not equal element by element, then the number of equality operations performed is the size of the range [ first1, i] , where i is the iterator referring to the first element in the range [ first1, last1) that does not match the corresponding element in the rangE the range of size n beginning at first2 ; otherwise, the number of equality operations performed is the size of the range [ first1, last1) .
Space complexity Constant.
Mutative? No.
Glossary terms BinaryPredicate, constant space, dereference type, function object, function object type, InputIterator, iterator, linear time, mutative, operator ==, predicate, range, sequence.
Example Select here to view the source code for the example.
Implementation Select here to view source code (Copyright (C) 1994, Hewlett-Packard Company) for this algorithm.