In the pub-sub model, a subscriber usually registers a callback that is being invoked when a message from a publisher is delivered to the subscriber.
In the preceding recipe, we created a mechanism to register callbacks using inheritance and abstract classes. It is not the only mechanism available in C++. Lambda functions available in C++, starting from the C++11 standard, can be used as an alternative solution. This eliminates lots of boilerplate code needed to define derived classes and, in most cases, allows developers to express their intent in a clearer way.
In this recipe, we will learn how to use C++ lambda functions to define callbacks.