#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int xform(int i) {
return i * i;
}
int main()
{
list<int> listObject;
int i;
for(i = 0; i <10; i++)
listObject.push_back(i);
cout << "Original contents of listObject: ";
list<int>::iterator p = listObject.begin();
while(p != listObject.end()) {
cout << *p << " ";
p++;
}
cout << endl;
p = transform(listObject.begin(), listObject.end(), listObject.begin(), xform);
cout << "Transformed contents of listObject: ";
p = listObject.begin();
while(p != listObject.end()) {
cout << *p << " ";
p++;
}
return 0;
}
|