We are continuing with the previous example, and now we want to use a lambda function with our process_integers()
method.
This recipe is continuing the series of the previous two. You must read them first. You will also need a C++11 compatible compiler or at least a compiler with C++11 lambda support.
Nothing needs to be done as boost::function<>
is also usable with lambda functions of any difficulty:
#include <deque> //#include "your_project/process_integers.h" void sample() { // lambda function with no parameters that does nothing process_integers([](int /*i*/){}); // lambda function that stores a reference std::deque<int> ints; process_integers([&ints](int i){ ints.push_back(i); }); // lambda function that modifies its content std::size_t match_count = 0; process_integers([ints, &match_count](int i) mutable { if (ints.front()...