Quantcast
Channel: How can I write a beautiful inline recursive lambda in C++? - Stack Overflow
Viewing all articles
Browse latest Browse all 6

Answer by sudo rm -rf slash for How can I write a beautiful inline recursive lambda in C++?

$
0
0

I'm not sure if this counts as beautiful, but you might consider this:

std::function<void(int)> dfs = [&](int x) -> void {    // ....    dfs(x);};dfs(0);

The compiler may be able to inline the std::function call, but only in simple cases. Of course, it cannot fully inline a recursive function.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>