Introduction

Functions, function objects and lamda functions are all part of the callable units class. They are 'called' to retrieve data or perform an action.

ℹ️ This chapter is intentionally not exhaustive
This course is about the C++ Standard library, therefore, it will no go into the details of callable units. I provide only as much information as it’s necessary to use them correctly in the algorithms of the Standard Template Library. An exhaustive discussion of callable units should be part of a course about the C++ core language.

Many of the STL algorithms and containers can be parametrized with callable units or short callables. A callable is something that behaves like a function. Not only are these functions but also function objects and lambda functions. Predicates are special functions that return a boolean as the result. If a predicate has one argument, it’s called a unary predicate if a predicate has two arguments, it’s called a binary predicate. The same holds for functions. A function taking one argument is a unary function; a function taking two arguments is a binary function.

🔑 To change the elements of a container, your algorithm must get them by reference
Callables can receive their arguments by value or by reference from their container. To modify the elements of the container, they must address them directly, so it is necessary that the callable gets them by reference.