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: artificial-mind.net/blog/2020/…
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: artificial-mind.net/blog/2020/…
Peter Vágner reshared this.
Gerald Squelart
in reply to Jamie Teh • • •Recursive lambdas from C++14 to C++23 - Notes from /dev/null
www.dev0notes.comSina Bahram
in reply to Jamie Teh • • •