// The function object multiplIEs an element by a Factor template <class Type> 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 void Operator ( ( Type& elem const { elem *= Factor; } };
int main( { using namespace std;
vector <int> v1;
//...
// Using for_each to multiply each element by a Factor for_each ( v1.begin ( , v1.end ( , MultValue<int> ( -2 ; }