Name
search_n function template — Searches a range for a repeated value
Synopsis
template<typename FwdIter, typename Size, typename T> FwdIter search_n(FwdIter first, FwdIter last, Size count, const T& value); template<typename FwdIter, typename Size, typename T, typename BinaryPredicate> FwdIter search_n(FwdIter first, FwdIter last, Size count, const T& value, BinaryPredicate pred);
The search_n
function
template finds the first (leftmost) subsequence of count
adjacent occurrences of value
in the range [first
, last
). It returns an iterator that points
to the start of the subsequence or last
if the subsequence is not
found.
The first form compares items with the ==
operator. The second form calls
pred(*iter
, value)
.
Technical Notes
The search_n
function
template returns first +
n, in which n is the smallest value in the range [0,
last - first) such that *(i + n + m) == value for all m in the range [0, count). It returns last if no such n can be found.
Complexity: at most n × (last - first) comparisons are performed.
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.