### unt311's blog

By unt311, history, 13 months ago,

        function<void()> dfs = [&](int a, int par, int depth) {
vis[a] = true;
if(depth > maxDepth){
maxDepth = depth;
farthestNode = a;
}
if(!vis[x])
dfs(x, a, 1 + dep);
}
};


I get the following error. error: no match for call to '(std::function<void()>) (long long int&, long long int&, long long int)'|

NOTE: changing a to &a and p to &p in parameter list does not make the error go away.

• +8

 » 13 months ago, # |   +5 I have #define int long long in the beginning of my code, in case you wonder where did long long come from.
 » 13 months ago, # |   +17 Try function  instead.
•  » » 13 months ago, # ^ |   0 that works, thanks a lot!!
 » 13 months ago, # |   +47 I like to write them like this: vi col(n); col[0] = 0; auto dfs = [&](int u, int p, auto&& dfs) -> void { for (int v : adj[u]) if (v != p) { col[v] = col[u] ^ 1; dfs(v, u, dfs); } }; dfs(0, -1, dfs); 
 » 7 months ago, # |   0 Can anyone have the link on how to write recursive lambda and related stuff?
•  » » 7 months ago, # ^ |   +1 What do you mean? How lightseba's answer not tutorial for recursive lambda?
•  » » » 7 months ago, # ^ |   0 i want to know more about lambda function(especially recursive) like why '&&' operater(not using && or single '&' also working) in ([&](int u, int p, auto&& dfs)) is used and many more...and yes lightseba's answer helped me to write recursive lambda function but i want know more that's why i asked for resources if anyone has..
•  » » » » 7 months ago, # ^ |   +5 If you ask about basic knowledge, then I think you can start here and thereRecursive lambda as lightseba's corresponds to C++14's generic lambdaIt's about labmda itself. About auto&& there no answer as I see. But you can see from paper that it is equivalent to template void operator()(int u, int p, Func&& dfs) { //... } And that syntax is about universal references. Can read some information here. Don't know whether there fuller paper about it but it is hard to understand topic.In fact in recursive calls passes lvalue reference to lambda. auto& must work too, difference there if std::move or rvalue used to pass lambda (may not compile). auto must work too, I'd say that difference here is that lambda is copying, but I can't reproduce it.
•  » » 7 months ago, # ^ |   0 i think you mean this