#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
template <typename elementType>
bool IsEven (const elementType& number)
{
return ((number % 2) == 0);
}
int main ()
{
vector <int> v;
for (int nNum = -9; nNum < 10; ++ nNum)
v.push_back (nNum);
vector <int>::const_iterator i;
for ( i = v.begin (); i != v.end (); ++ i )
cout << *i << ' ';
cout << v.size () << "' elements" << endl;
// Find the first even number in the collection
vector <int>::iterator iEvenNumber;
iEvenNumber = find_if ( v.begin ()// Start of range
, v.end () // End of range
, IsEven <int> ); // Unary Predicate
if (iEvenNumber != v.end ())
{
cout << "Number '" << *iEvenNumber << "' found at position [";
cout << distance (v.begin (), iEvenNumber);
cout << "]" << endl;
}
return 0;
}