Standard C++ Library Class Reference

Complexity
find peforms at most last-first comparisons.
Example
//
// find.cpp
//
#include <vector>
#include <algorithm>
int main()
{
typedef vector<int>::iterator iterator;
int d1[10] = {0,1,2,2,3,4,2,2,6,7};
// Set up a vector
vector<int> v1(d1,d1 + 10);
// Try find
iterator it1 = find(v1.begin(),v1.end(),3);
// it1 = v1.begin() + 4;
// Try find_if
iterator it2 =
find_if(v1.begin(),v1.end(),bind1st(equal_to<int>(),3));
// it2 = v1.begin() + 4
// Try both adjacent_find variants
iterator it3 = adjacent_find(v1.begin(),v1.end());
// it3 = v1.begin() +2
iterator it4 =
adjacent_find(v1.begin(),v1.end(),equal_to<int>());
// v4 = v1.begin() + 2
// Output results
cout << *it1 << " " << *it2 << " " << *it3 << " "
<< *it4 << endl;
return 0;
}
Output : 3 3 2 2
Warning
If your compiler does not support default template parameters then you need to always supply
the Allocator template argument. For instance you'll have to write:
vector<int,allocator>
instead of: