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.
greater has its operator() member defined such that it returns true if its first argument compares greater than the second one using operator>, and false otherwise.
This class is derived from binary_function and is defined as:
| 1 2 3 4 |
|
Objects of this class can be used with some standard algorithms such as sort, merge or lower_bound.
Members
- T operator() (const T& x, const T& y)
- Member function returning the result of the comparison x>y.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Output:
50 40 30 20 10 |
See also
| equal_to | Function object class for equality comparison (class template) |
| not_equal_to | Function object class for non-equality comparison (class template) |
| less | Function object class for less-than inequality comparison (class template) |
| greater_equal | Function object class for greater-than-or-equal-to comparison (class template) |
| less_equal | Function object class for less-than-or-equal-to comparison (class template) |
| binary_function | Binary function object base class (class template) |
