I have simple template metaprogramming class to calculate the bits set of a number:
template <int x>
struct BitsSet {
static const int n = BitsSet<(x >> 1)>::n + (x & 1);
};
template <>
struct BitsSet<0> {
static const int n = 0u;
};
Which works fine, but I'd like the template to be more flexible on the type holding the number, for example:
template <typename T, T x>
struct BitsSet {
static const T n = BitsSet<T, (x >> 1)>::n + (x & 1);
};
template <typename T>
struct BitsSet<T, 0> {
static const int n = 0u;
};
However the error is:
significant.h:32:12: error: template argument ‘(T)0’ involves template parameter(s)
32 | struct BitsSet<T, 0> {
I belive that it fails given the point (5) of the description for partial specialization Am I right?
As well there are several questions relating to this error, I think this solution being the closest... but honestly I am not capable to reach a solution to my problem.
A simplier question would be: how do you parametrize the int type in the typical factorial template calculation?