I have a function that searches a vector of iterators and returns the iterator if its names matches a string passed as an argument.
koalaGraph::PVertex lookUpByName(std::string Name, std::vector<koalaGraph::PVertex>& Vertices) {
for (size_t i = 0; i < Vertices.size(); i++) {
if(Vertices[i]->info.name == Name)
return Vertices[i];
}
}
My question is how can I implement this as a lambda, to use it in connection with std::find_if
?
I'm trying this:
std::vector<koalaGraph::PVertex> V;
std::string Name;
std::find_if(V.begin(), V.end(), [&Name]() {return Name == V->info.name;})
But it says that V
an enclosing-function local variable cannot be referenced in a lambda body unless it is in the capture list.