MORE ON FUNCTION OBJECTS

The functional header defines an extensive set of templates for creating function objects that you can use with algorithms and containers. I won’t discuss them in detail, but I’ll summarize the most useful ones. The function objects for comparisons are shown in the following table:

FUNCTION OBJECT TEMPLATE DESCRIPTION
less<T> Creates a binary predicate representing the < operation between objects of type T. For example, less<string>() defines a function object for comparing objects of type string.
less_equal<T> Creates a binary predicate representing the <= operation between objects of type T. For example, less_equal<double>() defines a function object for comparing objects of type double.
equal_to<T> Creates a binary predicate representing the == operation between objects of type T.
not_equal_to<T> Creates a binary predicate representing the != operation between objects of type T.
greater_equal<T> Creates a binary predicate representing the >= operation between objects of type T.
greater<T> Creates a binary predicate representing the > operation between objects of type T.
not2<B> Creates a binary predicate that is the negation of a binary predicate of type B. For example, not2(less<int>) creates a binary predicate for comparing objects of type int that returns true if the left operand is not less than the right operand. The template type parameter value B is deduced from the type of the constructor argument.

Here’s how you could use ...

Get Ivor Horton's Beginning Visual C++ 2012 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.