Search⌘ K

Call Multiple Lambdas with the Same Input

Learn to call multiple lambdas with the same input.

We'll cover the following...

We can easily create multiple instances of a lambda with different capture values by wrapping the lambda in a function. This allows us to call different versions of a lambda with the same input.

How to do it

This is a simple example of a lambda that wraps a value in different types of braces:

  • We’ll start by creating the wrapper function braces():

auto braces (const char a, const char b) {
return [a, b](const char v) {
cout << format("{}{}{} ", a, v, b);
};
}

The braces() function wraps a lambda that returns a three-value string, where the first and last ...