3 ms·
I don't know about that link, but in general you would use a fix point combinator. The Fit library has a fix point combinator here: http://pfultz2.github.io/Fi
by pfultz2 12y ago
I don't know about that link, but in general you would use a fix point combinator. The Fit library has a fix point combinator here:
http://pfultz2.github.io/Fit/doc/html/fix/ http://pfultz2.github.io/Fit/doc/html/fix/
So you could implement a generic factorial like this:
auto factorial = fit::fix([](auto self, auto x) -> decltype(x)
{
return x == 0 ? 1 : x * self(x-1);
});