// // This is example code from Chapter 21.2 "The simplest algorithm: find()" of // "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup // #include //using namespace std; using std::vector; //------------------------------------------------------------------------------ template In find(In first, In last, const T& val) // Find the first element in [first,last) that equals val { while (first!=last && *first != val) ++first; return first; } //------------------------------------------------------------------------------ void f(vector& v, int x) { vector::iterator p = ::find(v.begin(),v.end(),x); if (p!=v.end()) { // we found x in v } else { // no x in v } // ... } //------------------------------------------------------------------------------ int main() { int initializer[7] = {1,2,3,4,5,6,7}; int* first = initializer; int* last = initializer+7; vector v(first,last); f(v,4); } //------------------------------------------------------------------------------