#include
#include
#include
#include
using namespace std;
template
struct DisplayCounter
{
int m_nCount;
DisplayCounter ()
{
m_nCount = 0;
}
// Display the element, hold count!
void operator () (const elementType& element)
{
++ m_nCount;
cout << element << ' ';
}
};
int main ()
{
vector v;
for (int nCount = 0; nCount < 10; ++ nCount)
v.push_back (nCount);
DisplayCounter mResult;
mResult = for_each ( v.begin (), v.end (), DisplayCounter () );
cout << "'" << mResult.m_nCount << "' elements were displayed!" << endl;
return 0;
}