O'Reilly logo

The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. STL Function Objects

This chapter discusses in detail function objects, or functors for short, which were introduced in Section 5.9. It covers the full set of predefined function objects and function adapters, and the concept of functional composition, and provides examples of self-written function objects.

The Concept of Function Objects

A function object (or functor), is an object that has operator () defined so that in the following example

FunctionObjectType fo;
   ...
   fo(...);

the expression fo() is a call of operator () for the function object fo instead of a call of the function fo().

At first, you could consider a function object as an ordinary function that is written in a more complicated way: Instead of writing all the function statements ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required