I need to compute the product of a bunch of numbers at compile time, passed in a template structure. I managed to make the ugly decision:
template<std::size_t n1, std::size_t ...args> struct mul_all { static constexpr std::size_t value = n1 * mul_all<args...>; }; template<> struct mul_all<0> { static constexpr std::size_t value = 1; };
The problem is that every time I have to feed 0 into the template arguments for my structure, for example:
int main() { std::cout << mul_all<1,2,5,4,5,7,0>::value << " " << mul_all<4,2,0>::value; return 0; }
is there any workaround to read this last zero?
Note: I am starting in TMP.
source share