find_end
Prototypefind_end is an overloaded name; there are actually two find_end functions. template <class ForwardIterator1, class ForwardIterator2> ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate comp); DescriptionFind_end is misnamed: it is much more similar to search than to find, and a more accurate name would have been search_end.
Like
The two versions of
The first version of DefinitionDefined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.Requirements on typesFor the first version:
Preconditions
ComplexityThe number of comparisons is proportional to(last1 - first1) * (last2 - first2). If both ForwardIterator1 and ForwardIterator2 are models of BidirectionalIterator, then the average complexity is linear and the worst case is at most (last1 - first1) * (last2 - first2) comparisons. Exampleint main() { char* s = "executable.exe"; char* suffix = "exe"; const int N = strlen(s); const int N_suf = strlen(suffix); char* location = find_end(s, s + N, suffix, suffix + N_suf); if (location != s + N) { cout << "Found a match for " << suffix << " within " << s << endl; cout << s << endl; int i; for (i = 0; i < (location - s); ++i) cout << ' '; for (i = 0; i < N_suf; ++i) cout << '^'; cout << endl; } else cout << "No match for " << suffix << " within " << s << endl; } Notes[1] The reason that this range is[first1, last1 - (last2 - first2)), instead of simply [first1, last1), is that we are looking for a subsequence that is equal to the complete sequence [first2, last2). An iterator i can't be the beginning of such a subsequence unless last1 - i is greater than or equal to last2 - first2. Note the implication of this: you may call find_end with arguments such that last1 - first1 is less than last2 - first2, but such a search will always fail. See alsosearch | |||||||

