equal
Test whether two ranges are equal
You're viewing an older version of this page (#5923). View the current version.
Definition
The equal() algorithm is defined in the standard header <algorithm> and in the nonstandard backward-compatibility header <algo.h>.
Interface
#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 comp
);Parameters:
| Parameter | Description |
| first1 | An input iterator addressing the position of the first element in the first range to be tested |
| last1 | An input iterator addressing the position one past the final element in the first range to be tested |
| first2 | An input iterator addressing the position of the first element in the second range to be tested |
| comp | User-defined predicate function object that defines the condition to be satisfied if two elements are to be taken as equivalent. A binary predicate takes two arguments and returns true when satisfied and false when not satisfied |
Description
Compares two ranges element by element either for equality or equivalence in a sense specified by a binary predicate.
Return Value
The first version of equal returns true if and only if for every iterator i in [first1, last1), *i == *(first2 + (i - first1)).
The second version of equal returns true if and only if for every iterator i in [first1, last1), comp(*i, *(first2 + (i - first1))) is true.
Complexity
The time complexity of the algorithm is linear in the number of elements contained in the range, at most last1 - first1 comparisons.
References
See Also
- http://www.codecogs.com/reference/computing/stl/algorithms/nonmodifying/mismatch.php"mismatch"
- http://www.codecogs.com/reference/computing/stl/algorithms/nonmodifying/search.php"search"
- http://www.codecogs.com/reference/computing/stl/algorithms/nonmodifying/find.php"find"
- http://www.codecogs.com/reference/computing/stl/algorithms/nonmodifying/find_if.php"find_if"