Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

adjacent_find


Algorithm

Summary

Find the first adjacent pair of elements in a sequence that are equivalent.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <algorithm>
template <class ForwardIterator>
  ForwardIterator
  adjacent_find(ForwardIterator first, 
                ForwardIterator last);

template <class ForwardIterator, class BinaryPredicate>
 ForwardIterator
  adjacent_find(ForwardIterator first, ForwardIterator last,
                BinaryPredicate pred);

Description

There are two versions of the adjacent_find algorithm. The first finds equal adjacent elements in the sequence defined by iterators first and last and returns an iterator i pointing to the first of the equal elements. The second version lets you specify your own binary function to test for a condition. It returns an iterator i pointing to the first of the pair of elements that meet the conditions of the binary function. In other words, adjacent_find returns the first iterator i such that both i and i + 1 are in the range [first, last) for which one of the following conditions holds:

*i == *(i + 1)

or

pred(*i,*(i + 1)) == true

If adjacent_find does not find a match, it returns last.

Complexity

adjacent_find performs exactly find(first,last,value) - first applications of the corresponding predicate.

Example

Program Output :

Warnings

If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you have to write:

vector<int,allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

find



Previous fileTop of documentContentsIndexNext file
Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998