3 ms·
You can also compute the factorials at compile time with templates: template<int64_t n> int64_t fact() { return n * fact<n-1>(); } template<> int64_t fact<0>()
by arbre 11y ago
You can also compute the factorials at compile time with templates:
template<int64_t n> int64_t fact() { return n * fact<n-1>(); }
template<> int64_t fact<0>() { return 1; }
The book "Modern C++ design" from Alexandrescu extensively covers that kind of stuff.
There might even be a way to use a loop and constexprs.
- wyager 11y agoWon't most modern compiled languages statically evaluate constant numerical expressions?