Function Object (Also Known As A Functor) : - STL Function Objects Support Function Call Syntax
Function Object (Also Known As A Functor) : - STL Function Objects Support Function Call Syntax
• Refines Assignable
• Abstracts 0-ary functions (take no arguments)
• Valid Expressions
– Function call signature with no arguments
f()
• Semantics
– Returns some value of type Result
– Different invocations may return different values
• Or, can represent a constant as a 0-ary functor
– Invocation may change the function object’s internal state
• So, operator() need not be a const member function
// random values
generate(v1.begin(), v1.end(), rand);
transform(v1.begin(), v1.end(),
v2.begin(),
bind1st(plus<double>(), 3.0));
struct D1 : public B {
void print() { cout << "I'm a D1" << endl; } };
struct D2 : public B {
void print() { cout << "I'm a D2" << endl; } };