#include
#include
#include
#include
using namespace std;
// A simple function object.
class reciprocal: unary_function {
public:
result_type operator()(argument_type i) {
return (result_type) 1.0/i; // return reciprocal
}
};
int main()
{
list listObject;
int i;
for(i = 1; i <10; i++)
listObject.push_back((double)i);
cout << "Original contents of listObject:\n";
list::iterator p = listObject.begin();
while(p != listObject.end()) {
cout << *p << " ";
p++;
}
cout << endl;
// use reciprocal function object
// call function object
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;
}