Given a matrix class
using index_t = int;
template<index_t M, index_t N, typename S>
struct mat {
// matrix implementation
};
I would like to have a generic way of obtaining the elementCount for a given type T
that will work for both matrices and scalars. For example, I imagine being able to do this:
dimensionality<mat<1,2,double>>(); // returns 2
dimensionality<mat<2,2,float>>(); // returns 4
dimensionality<double>(); // returns 1
or perhaps something like this:
attributes<mat<1,2,double>>::dimensionality; // returns 2
attributes<mat<2,2,float>>::dimensionality; // returns 4
attributes<double>::dimensionality; // returns 1
My attempt:
I tried doing the following (thinking that I am partially specializing the struct attributes
):
template<typename T>
struct attributes {};
template<typename S, typename = std::enable_if_t<std::is_arithmetic<S>::value>>
struct attributes<S> { // <--- compiler error on this line
static constexpr index_t dimensionality = 1;
};
template<index_t M, index_t N, typename S>
struct attributes<mat<M, N, S>> {
static constexpr index_t dimensionality = M * N;
};
but I get a compiler error on the indicated line. Can you help me (either by suggesting a better approach, or to understand what I'm doing wrong)?