#include #include #include #include #include using namespace std; template class MultValue { private: Type Factor; // The value to multiply by public: // Constructor initializes the value to multiply by MultValue ( const Type& _Val ) : Factor ( _Val ) { } // The function call for the element to be multiplied int operator ( ) ( Type& elem ) const { return elem * Factor; } }; class Person{ public: string f, l; int age; Person():f(""),l(""),age(0){} Person(string fn, string ln, int a):f(fn),l(ln),age(a){} }; bool operator <(const Person &p, const Person &q){ return p.age < q.age; } class Age { public: // The function call for the element to be multiplied Person& operator ( ) ( Person & p ) const { p.age++; return p; } }; void main(){ vector v; for(int i = 0; i < 10; i++) v.push_back(i); for(int i = 0; i < 10; i++) cout << v[i] << endl; transform(v.begin(),v.end(), v.begin(), MultValue(3)); cout << "Transformed " << endl; for(int i = 0; i < 10; i++) cout << v[i] << endl; Person bill("Bill", "Wilson", 42); Person sue("Sue", "Smith", 44); set< Person> s; s.insert(bill); s.insert(sue); transform(s.begin(), s.end(), s.begin(), Age()); set::iterator it; for(it = s.begin(); it != s.end(); it++) cout << (*it).f << (*it).l << (*it).age << endl; }