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