T
ticapix
I wrote this little code which doesn't compile:
"main.cpp:46: erreur: function template partial specialization"
//// ------------------ BEGIN ------------------ ////
#include <iostream>
struct kernel {
int length;
int coords[9][2];
};
static const kernel g_kernels[2] = {
{2, {{-1, 0}, {1, 0}}},
{2, {{0, -1}, {0, 1}}},
};
template<int idx, int length>
/*inline*/ char ApplyKernel(unsigned char* buff) {
std::cout << g_kernels[idx].coords[length-1][1] << ", " <<
g_kernels[idx].coords[length-1][0] << std::endl;
return ApplyKernel<idx, length-1>(buff);
}
template<int idx>
/*inline*/ char ApplyKernel<idx, 0>(unsigned char* buff) {
std::cout << g_kernels[idx].coords[0][1] << ", " <<
g_kernels[idx].coords[0][0] << std::endl;
return 0;
}
typedef char (apply_t)(unsigned char* buff);
apply_t *fcts[] = {
ApplyKernel<0, 2-1>,
ApplyKernel<1, 2-1>
};
static unsigned char buff[999];
int main(void) {
fcts[0]((unsigned char*)buff);
fcts[1]((unsigned char*)buff);
return 0;
}
//// ------------------ END ------------------ ////
I'm trying to unroll the loop for, but I can figure out how to
specialize a "stop" template method like:
template<int idx>
char ApplyKernel<idx, 0>(unsigned char* buff) {...};
How can I bypass this restriction ?
"main.cpp:46: erreur: function template partial specialization"
//// ------------------ BEGIN ------------------ ////
#include <iostream>
struct kernel {
int length;
int coords[9][2];
};
static const kernel g_kernels[2] = {
{2, {{-1, 0}, {1, 0}}},
{2, {{0, -1}, {0, 1}}},
};
template<int idx, int length>
/*inline*/ char ApplyKernel(unsigned char* buff) {
std::cout << g_kernels[idx].coords[length-1][1] << ", " <<
g_kernels[idx].coords[length-1][0] << std::endl;
return ApplyKernel<idx, length-1>(buff);
}
template<int idx>
/*inline*/ char ApplyKernel<idx, 0>(unsigned char* buff) {
std::cout << g_kernels[idx].coords[0][1] << ", " <<
g_kernels[idx].coords[0][0] << std::endl;
return 0;
}
typedef char (apply_t)(unsigned char* buff);
apply_t *fcts[] = {
ApplyKernel<0, 2-1>,
ApplyKernel<1, 2-1>
};
static unsigned char buff[999];
int main(void) {
fcts[0]((unsigned char*)buff);
fcts[1]((unsigned char*)buff);
return 0;
}
//// ------------------ END ------------------ ////
I'm trying to unroll the loop for, but I can figure out how to
specialize a "stop" template method like:
template<int idx>
char ApplyKernel<idx, 0>(unsigned char* buff) {...};
How can I bypass this restriction ?