In my class lots of methods have such a snippet:
std::string str = getSomeStr();
auto it = std::find_if(
vec.begin(),
vec.end(),
[str](const std::string& b){return str + "abc" == b;});
Therefore, I want to store the lambda function to reuse it. But it captures the str
from the scope. How I should do that?
If I understood it right...
Usage:
You don't have to use the
str
temporary, or makeMyOperation
hold only astd::string
reference. This depends on what do you want to achieve.of course technically you can do this:
But I don't see the point, frankly.
How about a capture by reference and then assign to that reference before each use: