.\" ident @(#)adjacent_find.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH adjacent_find 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2adjacent_find\fP \ - Find the first adjacent pair of elements in a sequence that are equivalent. .SH SYNOPSIS .br #include .br template .RE .RS 1 ForwardIterator .br adjacent_find(ForwardIterator first, .RE .RS 15 ForwardIterator last); .RE .RS 0 .br template .br ForwardIterator .RE .RS 1 adjacent_find(ForwardIterator first, ForwardIterator last, .RE .RS 15 BinaryPredicate pred); .SH DESCRIPTION There are two versions of the adjacent_find algorithm. The first finds equal adjacent elements in the sequence defined by iterators \f2first\fP and \f2last\fP and returns an iterator \f2i\fP 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 \f2i\fP 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 \f2i\fP such that both \f2i\fP and \f2i + 1\fP are in the range \f2[first, last)\fP for which one of the following conditions holds: \f2*i == *(i + 1)\fP or \f2pred(*i,*(i + 1)) == true\fP If adjacent_find does not find a match, it returns \f2last\fP. .SH COMPLEXITY adjacent_find performs exactly \f2find(first,last,value) - first\fP applications of the corresponding predicate. .SH EXAMPLE .RE .RS 0 // .br // find.cpp .br // .br #include .br #include .br #include .br using namespace std; .br .br int main() .RE .RS 1 { .RE .RS 2 typedef vector::iterator iterator; .br int d1[10] = {0,1,2,2,3,4,2,2,6,7}; .RE .RS 0 .RE .RS 3 // Set up a vector .RE .RS 2 vector v1(d1,d1 + 10); .RE .RS 0 .RE .RS 3 // Try find .RE .RS 2 iterator it1 = find(v1.begin(),v1.end(),3); .RE .RS 0 .RE .RS 3 // Try find_if .RE .RS 2 iterator it2 = .RE .RS 3 find_if(v1.begin(),v1.end(),bind1st(equal_to(),3)); .RE .RS 0 .RE .RS 3 // Try both adjacent_find variants .RE .RS 2 iterator it3 = adjacent_find(v1.begin(),v1.end()); .RE .RS 0 .RE .RS 2 iterator it4 = .RE .RS 5 adjacent_find(v1.begin(),v1.end(),equal_to()); .RE .RS 0 .RE .RS 3 // Output results .RE .RS 2 cout << *it1 << " " << *it2 << " " << *it3 << " " .RE .RS 8 << *it4 << endl; .RE .RS 0 .RE .RS 2 return 0; .RE .RS 1 } .br .RE .RS 0 Program Output : .RE .RS 0 .br 3 3 2 2 .SH WARNINGS If your compiler does not support default template parameters, then you always need to supply the \f2Allocator\fP template argument. For instance, you have to write: \f2vector >\fP instead of: \f2vector\fP If your compiler does not support namespaces, then you do not need the using declaration for \f2std\fP. .SH SEE ALSO find