The first example below fixes a few problems with the original source and shows a way of specializing the behavior and interface of a nested template without specializing the enclosing class. (I just modified the source you posted. It hasn't been styled.)
The second example shows recursion on a second integer value. It is as strait forward as you probably think. It isn't, or at least shouldn't be, the recursion giving you a problem.
If you need more help, you'll have to post more source. We can't guess at the missing bits.
Soma
Code:
template <int nrows, int ncols, int ld = nrows>
class cmatrix {
public:
float *val ; // pointer to the data on the device
/* a bunch of code */
template <int uld>
inline void mgso( cupper<ncols,uld> &R);
} ;
/* cupper is a derived class from cmatrix */
template<int nrows, int ld = nrows>
class cupper : public cmatrix<nrows,nrows,ld> {
public:
inline float *subptr()
{
return((this->val)+1+ld) ;
}
cupper<nrows-1,ld> sub()
{
return(subptr()) ;
}
/* other stuff like constructors and destructors etc. */
} ;
template <int nrows, int ncols, int ld, int uld>
struct cmatrix__mgso_implementation
{
static inline void execute( cupper<ncols,uld> &R)
{
if (ncols > 1) {
/* recurse over the remaining columns */
cmatrix<nrows,ncols-1,ld> X1(ptroff(0,1)) ;
/* ... */
/* recursion starts here */
X1.mgso(rsub) ;
}
}
};
template <int nrows, int ld, int uld>
struct cmatrix__mgso_implementation<nrows, 0, ld, uld>
{
static inline void execute( cupper<0,uld> &R)
{
// specialization for 'cmatrix<nrows, ncols, ld>::mgso' ncols = 0 here
}
};
template <int nrows, int ncols, int ld> template <int uld>
inline void cmatrix<nrows, ncols, ld>::mgso( cupper<ncols,uld> &R)
{
cmatrix__mgso_implementation<nrows, ncols, ld, uld>::execute(R);
}
Code:
#include <iostream>
template
<
unsigned int x_F,
unsigned int y_F
>
struct test: test<x_F, y_F - 1>
{
test()
{
std::cout << '(' << x_F << ',' << y_F << ')' << '\n';
}
};
template
<
unsigned int x_F
>
struct test<x_F, 0>
{
test()
{
std::cout << '(' << x_F << ',' << 0 << ')' << '\n';
}
};
int main()
{
test<5, 5> a;
}