Is it possible to deduce a non-type template parameter from a template function parameter?
Consider this simple template:
template <int N> constexpr int factorial()
{
return N * factorial<N - 1>();
}
template <> constexpr int factorial<0>()
{
return 1;
}
template <> constexpr int factorial<1>()
{
return 1;
}
I would like to be able to change factorial
so that I can alternatively call it like this:
factorial(5);
and let the compiler figure out the value of N at compile time. Is this possible? Maybe with some fancy C++11 addition?
See Question&Answers more detail:os