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 parameter which is a bit ugly. And I doubt the possibility for the compiler to make it inline. Are there new options in new C++ standards? (C++20 or C++23)
self
parameter. – Moatstd::function
is used, there will be performance lost. – Memorialiststruct { int& capture1; void operator()(int x) const { ...; (*this)(x); } } dfs{ captured1 };
, where you have access to*this
of the functor – Overpassstruct Foo { int x{}; Foo foo; };
being infinite in size.) – Normalie