concept lambda in category c++

This is an excerpt from Manning's book Functional Programming in C++.
Fortunately, C++ has lambdas, which are syntactic sugar for creating anonymous (unnamed) function objects. Lambdas allow you to create function objects inline—at the place where you want to use them—instead of outside the function you’re currently writing. Let’s see this in an example from earlier: you have a group of people, and you want to collect only females from that group (see figure 3.3).
Figure 3.3 Getting all females from a group of people. You’ve been using a predicate called
is_female, which is a non-member function for this. Now you’re going to do the same with a lambda.![]()
One thing worth noting is that the call operator of lambdas is constant by default (contrary to the other parts of the language, where you need to explicitly specify that something is
const). If you want to change the value of the captured variables, when they’re captured by value and not by reference, you’ll need to declare the lambda asmutable. In the following example, you use thestd::for_eachalgorithm to write all words beginning with an uppercase letter, and you use thecountvariable to count the number of words you wrote. This is sometimes useful for debugging, but mutable lambdas should be avoided. Obviously, there are better ways to do this, but the point here is to demonstrate how mutable lambdas work.Listing 3.5 Creating a mutable lambda
int count = 0; std::vector<std::string> words{"An", "ancient", "pond"}; std::for_each(words.cbegin(), words.cend(), [count] #1 (const std::string& word) mutable #2 { if (isupper(word[0])) { std::cout << word << " " << count <<std::endl; count++; } } ); #1 You’re capturing “count” by value; all changes to it are localized and visible only from the lambda. #2 mutable comes after the argument list and tells the compiler that the call operator on this lambda shouldn’t be const.