- What is the simplest lambda you can write?
The simplest lambda receives no parameters and returns a constant; it can be something like the following:
auto zero = [](){return 0;};
- How can you write a lambda that concatenates two string values passed as parameters?
There are a few variations to this answer, depending on your preferred way of concatenating strings. The simplest way using STL is as follows:
auto concatenate = [](string first, string second){return first + second;};
- What if one of the values is a variable that's captured by value?
The answer is similar to the preceding solution, but using the value from context:
auto concatenate = [first](string second){return first + second;};
Of course, we can also use the default capture by value notation, as follows:
auto concatenate = [=](string second){return first + second;};
- What if one of the values is...