// The "function parameters" passed to the algorithm may not necessarily be functions, but objects that act like functions. This type of object is called a function object or a functor (function-like) object ).
// C ++ standard library 5.9 functor = function object // # include <iostream> # include <vector> # include <algorithm> using namespace STD; class printint {public: void operator () (int elem) const {cout <ELEM <";}}; template <class iterator, class operation> operation for_each _ (iterator act, iterator end, Operation OP) {While (act! = END) {OP (* Act); ++ Act;} return op;} int main () {vector <int> F; vector <int >:: iterator fit; printint pint; For (INT I = 0; I <10; ++ I) {f. push_back (I);} // for_each (F. begin (), F. end (), printint ();/* For (fit = f. begin (); fit! = F. end (); ++ fit) {pint (* fit); // call through the object} */for_each _ (F. begin (), F. end (), printint (); // a temporary printint type object will be generated. Return 0 ;}