Function objects

A function object, or functor, is a custom type that implements the function call operator: (operator()). This means that a function operator can be called in a way that looks like it is a function. Since we haven't covered classes yet, in this section we will just explore the function objects types that are provided by the Standard Library and how to use them.

The <functional> header file contains various types that can be used as function objects. The following table lists these:

Purpose Types
Arithmetic divides, minus, modulus, multiplies, negate, plus
Bitwise bit_and, bit_not, bit_or, bit_xor
Comparison equal_to, greater, greater_equal, less, less_equals, not_equal_to
Logical logical_and, logical_not, logical_or ...

Get Beginning C++ Programming 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.