Generically, function objects are instances of a class with member function operator() defined. This member function allows the object to be used with the same syntax as a regular function call, and therefore it can be used in templates instead of a pointer to a function.
In the case of unary function objects, this operator() member function takes one single parameter.
unary_function is just a base class, from which specific unary function objects are derived. It has no operator() member defined (derived classes are expected to define this) - it simply has two public data members that are typedefs of the template parameters. It is defined as:
| 1 2 3 4 5 |
|
Members
- argument_type
- Alias of the first template parameter, which is the type for the argument in member operator().
- result_type
- Alias of the second template parameter, which is the return type in member operator().
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Possible output:
Please enter a number: 2 Number 2 is even. |
See also
| binary_function | Binary function object base class (class template) |
