Quantcast
Browsing latest articles
Browse All 6 View Live

Answer by sudo rm -rf slash for How can I write a beautiful inline recursive...

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...

View Article


Answer by Artyer for How can I write a beautiful inline recursive lambda in C++?

You can use an explicit object parameter with a deduced type:auto dfs = [&](this const auto &self, int x) -> void { // .... self(x);};dfs(0); // `self` is `dfs`This is a C++23 feature

View Article


How can I write a beautiful inline recursive lambda in C++?

As I know in C++17, I can write a recursive lambda like this:auto dfs = [&](const auto &self, int x) -> void { // .... self(self, x);};dfs(dfs, 0);Unfortunately, I have to endure one more...

View Article

Answer by Neil for How can I write a beautiful inline recursive lambda in C++?

If you don't have access to C++23 then you can wrap your lambda in another lambda that hides the extra argument, e.g. like this:int main(int argc, char **argv) { auto fact = [&](int x) -> int {...

View Article
Browsing latest articles
Browse All 6 View Live


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