adjacent_find function template — Searches for a pair of adjacent, equal items
template<typename FwdIter> FwdIter adjacent_find(FwdIter first, FwdIter last); template<typename FwdIter, typename BinaryPredicate> FwdIter adjacent_find(FwdIter first, FwdIter last, BinaryPredicate pred);
The adjacent_find
function
template looks for the first set of adjacent items in the range
[first
, last
) that are equal (first version) or in
which pred(*iter
, *(iter+1))
is true (second version). Items
are "adjacent" when their iterators differ by one position.
The return value is an iterator that points to the first of
the adjacent items, or last
if no
matching items are found. See Figure 13-1 for an
example.
The adjacent_find
function
template returns i
, in which
i
= first
+ n
, and n
is the smallest value such that
*(first
+ n
) == *(first
+ n
+ 1) and first
+
n
+ 1 < last
, or,
if there is no such n
,
i
= last
.
Complexity is linear: the standard is muddled, but any
reasonable implementation calls the predicate (operator==
or pred
) exactly n
+ 1 times.