I am trying to optimize my math calculation code base and I found this piece of code from here
this piece of code tries to calculate the matrix multiplication. However, I don't understand how enum can be used for calculation here. Cnt is a type specified in
template <int I=0, int J=0, int K=0, int Cnt=0> 
and somehow we can still do
Cnt = Cnt + 1
Could anyone give me a quick tutorial on how this could be happening?
Thanks
template <int I=0, int J=0, int K=0, int Cnt=0> class MatMult
    {
    private :
        enum
            {
            Cnt = Cnt + 1,
            Nextk = Cnt % 4,
            Nextj = (Cnt / 4) % 4,
            Nexti = (Cnt / 16) % 4,
            go = Cnt < 64
            };
    public :
        static inline void GetValue(D3DMATRIX& ret, const D3DMATRIX& a, const D3DMATRIX& b)
            {
            ret(I, J) += a(K, J) * b(I, K);
            MatMult<Nexti, Nextj, Nextk, Cnt>::GetValue(ret, a, b);
            }
    };
// specialization to terminate the loop
template <> class MatMult<0, 0, 0, 64>
    {
    public :
        static inline void GetValue(D3DMATRIX& ret, const D3DMATRIX& a, const D3DMATRIX& b) { }
};
Or maybe I should ask more specifically, how does Nexti, Nextj, Nextk, Cnt get propagated to the next level when the for loop is unrolled.
thanks
