Standard C++ Library Class Reference

BinaryPredicate binary_pred);
template <class ForwardIterator,
class Size,
class T>
ForwardIterator search_n (ForwardIterator first,
ForwardIterator last,
Size count, const T& value);
template <class ForwardIterator,
class Size,
class T,
class BinaryPredicate>
ForwardIterator search_n (ForwardIterator first,
ForwardIterator last,
Size count, const T& value,
BinaryPredicate pred)
Description
The search and search_n are used for searching for a subsequence within a sequence. The
search algorithm searches for a subsequence [first2, last2) within a sequence [first1, last1), and
returns the beginning location of the subsequence. If it does not find the subsequence, search
returns last1. The first version of search uses the equality (==) operator as a default, and the
second version allows you to specify a binary predicate to perform the comparison.
The search_n algorithm searches for the subsequence composed of count occurrences of value
within a sequence [first, last), and returns first if this subsequence is found. If it does not find
the subsequence, search_n returns last. The first version of search_n uses the equality (==)
operator as a default, and the second version allows you to specify a binary predicate to perform
the comparison.
Complexity
search performs at most (last1 - first1)*(last2-first2) applications of the corresponding
predicate.
search_n performs at most (last - first) applications of the corresponding predicate.
Example
//
// search.cpp
//
#include <algorithm>
#include <list>
#include <iostream.h>