.\" ident @(#)find.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH find 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2find\fP \ - Finds an occurrence of value in a sequence. .SH SYNOPSIS .br #include .br template .RE .RS 1 InputIterator find(InputIterator first, .RE .RS 21 InputIterator last, .br const T& value); .SH DESCRIPTION The find algorithm lets you search for the first occurrence of a particular value in a sequence. find_returns the first iterator \f2i\fP in the range \f2[first, last)\fP for which the following condition holds: \f2*i == value. \fP If find does not find a match for \f2value\fP, it returns the iterator \f2last\fP. Type \f2T\fP must be EqualityComparable. .SH COMPLEXITY find performs at most \f2last-first\fP comparisons. .SH EXAMPLE .RE .RS 0 // .br // find.cpp .br // .RE .RS 1 #include .br #include .br #include .br #include .RE .RS 0 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 3 // it1 = v1.begin() + 4; .RE .RS 0 .RE .RS 3 // Try find_if .RE .RS 2 iterator it2 = .br find_if(v1.begin(),v1.end(),bind1st(equal_to(),3)); .RE .RS 3 // it2 = v1.begin() + 4 .RE .RS 0 .RE .RS 3 // Try both adjacent_find variants .RE .RS 2 iterator it3 = adjacent_find(v1.begin(),v1.end()); .RE .RS 3 // it3 = v1.begin() +2 .RE .RS 0 .br .RE .RS 2 iterator it4 = .RE .RS 5 adjacent_find(v1.begin(),v1.end(),equal_to()); .RE .RS 3 // v4 = v1.begin() + 2 .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 adjacent_find, find_first_of, find_if