Standard C++ Library Class Reference
Description
The find_end algorithm finds the last occurrence of a subsequence, indicated by [first2, last2), in a
sequence, [first1,last1). The algorithm returns an iterator pointing to the first element of the found
subsequence, or last1 if no match is found.
More precisely, the find_end algorithm returns the last iterator i in the range [first1, last1 -
(last2-first2)) such that for any non-negative integer n < (last2-first2), the following corresponding
conditions hold:
*(i+n) == *(first2+n),
pred(*(i+n),*(first2+n)) == true.
Or returns last1 if no such iterator is found.
Two versions of the algorithm exist. The first uses the equality operator as the default binary predicate,
and the second allows you to specify a binary predicate.
Complexity
At most (last2-first2)*(last1-first1-(last2-first2)+1) applications of the corresponding predicate are
done.
Example
//
// find_end.cpp
//
#include<vector>
#include<iterator>
#include<algorithm>
#include<iostream.h>
int main()
{
typedef vector<int>::iterator iterator;
int d1[10] = {0,1,6,5,3,2,2,6,5,7};
int d2[4] = {6,5,0,0}
//
// Set up two vectors.
//
vector<int> v1(d1+0, d1+10), v2(d2+0, d2+2);
//
// Try both find_first_of variants.
//
iterator it1 = find_first_of (v1.begin(), v1.end(), v2.begin(),
v2.end());
iterator it2 = find_first_of (v1.begin(), v1.end(), v2.begin(),
v2.end(), equal_to<int>());
//