I recently had a need for a recursive C++ lambda that captures variables. This isn't possible in the intuitive way; you get:
error: variable 'someVar' declared with deduced type 'auto' cannot appear in its own initializer.
It turns out you can achieve this (albeit a bit horribly) by passing the lambda to itself! See this article for details: https://artificial-mind.net/blog/2020/09/12/recursive-lambdas
Recursive Lambdas in C++

auto fib = [](int n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); }; auto i = fib(7); If only it were that simple. Obviously, any performance-conscious programmer will compute Fibonacci numbers iteratively (or even explicitly), but this solution will serve as an

artificial::mind blog
@jcsteh If you can use C++23, deducing-this makes it easier: https://www.dev0notes.com/intermediate/recursive_lambdas.html
Recursive lambdas from C++14 to C++23 - Notes from /dev/null

There are algorithms that have natural recursive representation and are very cumbersome or painful to write iteratively. With the advent of lambda expression...

@jcsteh Lol, I think this post encapsolates my distaste for C++ in a single go. Still fond of it, since it was my first programming language, but also, just ick :). Good luck, sir.