Function objects

operator() () Function

Function objects are objects with an operator() defined. They are important for the effective use of the library. In the places where one would expect to pass a pointer to a function to an algorithmic template, the interface is specified to accept an object with an operator() defined. This not only makes algorithmic templates work with pointers to functions, but also enables them to work with arbitrary function objects. Using function objects together with function templates increases the expressive power of the library as well as, making the resulting code much more efficient. For example, to have a by-element addition of two vectors a and b containing double and put the result into a do:

transform (a.begin(), a.end(), b.begin(), a.begin(), plus());

To negate every element of a do:

transform (a.begin(), a.end(), a.begin(), negate());

argument_type Typedef on unary_function
result_type Typedef on unary_function
first_argument_type Typedef on binary_function
second_argument_type Typedef on binary_function
result_type Typedef on binary_function
The corresponding functions will inline the addition and the negation. To enable adaptors and other components to manipulate function objects that take one or two arguments it is required that they correspondingly provide typedefs argument_type and result_type for function objects that take one argument and first_argument_type, second_argument_type, and result_type for function objects that take two arguments.