Function object: Difference between revisions

Content deleted Content added
The prior version stated "A C program using function pointers may appear as:". This is cumbersome. Also, stating "A C" is confusing; the edit specifies that C refers to the language.
Line 127:
In addition to class type functors, other kinds of function objects are also possible in C++. They can take advantage of C++'s member-pointer or [[generic programming|template]] facilities. The expressiveness of templates allows some [[functional programming]] techniques to be used, such as defining function objects in terms of other function objects (like [[function composition (computer science)|function composition]]). Much of the C++ [[Standard Template Library]] (STL) makes heavy use of template-based function objects.
 
'''=== Maintaining state ==='''
Another advantage of function objects is their ability to maintain a state that affects <code>operator()</code> between calls. For example, the following code defines a [[generator (computer science)|generator]] counting from 10 upwards and is invoked 11 times.