std::search_n

From cppreference.com
 
 
 
Defined in header <algorithm>
template< class ForwardIterator, class Size, class T >

ForwardIterator1 search_n( ForwardIterator first, ForwardIterator last,

                           Size count, const T& value );
(1)
template< class ForwardIterator, class Size, class T, class BinaryPredicate >

ForwardIterator1 search_n( ForwardIterator first, ForwardIterator last,

                           Size count, const T& value, BinaryPredicate p );
(2)

Searches the range [first, last) for the first sequence of count identical elements, each equal to the given value value. The first version uses operator== to compare the elements, the second version uses the given binary predicate p.

Contents

[edit] Parameters

first, last - the range of elements to examine
count - the length of the sequence to search for
value - the value of the elements to search for
p - binary predicate which returns ​true if the elements should be treated as equal.

The signature of the predicate function should be equivalent to the following:

bool pred(const Type1 &a, const Type2 &b);

The signature does not need to have const &, but the function must not modify the objects passed to it.
The type  Type1 must be such that an object of type ForwardIterator1 can be dereferenced and then implicitly converted to  Type1. The type  Type2 must be such that an object of type T can be implicitly converted to  Type2.

[edit] Return value

iterator to the beginning of the found sequence in the range [first, last). If no such sequence is found, last is returned.

[edit] Complexity

At most last - first applications of the predicate.

[edit] Possible implementation

[edit] Example

[edit] See also

finds the last sequence of elements in a certain range
(function template)
finds the first element satisfying specific criteria
(function template)
searches for a range of elements
(function template)