I wrote a smal example illustrating the problem. solve_bs1_y
and solve_bs2_y
are implemented completely similar. The only difference is the function call: solve_bs*_z
. Unfortunately, it seems impossible to pass a template as argument to replace the function call of solve_bs*_z
. Consequently, I have to implement for each solve_bs*_z
another solve_bs*_y
. Is there a way to simplify the code so that I need just one implementation of solve_bs_y
?
// Example program
#include <iostream>
#include <string>
template <int x, int y, int offs, class T>
float solve_bs1_z(T mat, float fS, float fT, float fU) {
return 1; // to keep it simple
}
template <int x, int y, int offs, class T>
float solve_bs2_z(T mat, float fS, float fT, float fU) {
return 2; // to keep it simple
}
// essentially the same as solve_bs2_y
template <int x, int offs, class T>
float solve_bs1_y(T mat, float fS, float fT, float fU) {
const float bs_s = 2;
return ( solve_bs1_z<x, 0, offs>(mat, fS, fT, fU)
+ solve_bs1_z<x, 1, offs>(mat, fS, fT, fU)
+ solve_bs1_z<x, 2, offs>(mat, fS, fT, fU))
* bs_s;
}
// essentially the same as solve_bs1_y
template <int x, int offs, class T>
float solve_bs2_y(T mat, float fS, float fT, float fU) {
const float bs_s = 2;
return ( solve_bs2_z<x, 0, offs>(mat, fS, fT, fU)
+ solve_bs2_z<x, 1, offs>(mat, fS, fT, fU)
+ solve_bs2_z<x, 2, offs>(mat, fS, fT, fU) )
* bs_s;
}
// these are called in the program ..
template<int offs, class T>
float solve_ffd_bs1(T mat, float fS, float fT, float fU) {
return solve_bs1_y<0, offs>(mat, fS, fT, fU) +
solve_bs1_y<1, offs>(mat, fS, fT, fU) +
solve_bs1_y<2, offs>(mat, fS, fT, fU);
}
template<int offs, class T>
float solve_ffd_bs2(T mat, float fS, float fT, float fU) {
return solve_bs2_y<0, offs>(mat, fS, fT, fU) +
solve_bs2_y<1, offs>(mat, fS, fT, fU) +
solve_bs2_y<2, offs>(mat, fS, fT, fU);
}
int main()
{
int mat[3][3][3] = {
{{1,2,3}, {4,5,6}, {7,8,9}},
{{11,2,3}, {14,5,6}, {17,8,9}},
{{21,2,3}, {24,5,6}, {27,8,9}}
};
solve_ffd_bs2<0>(mat, 1,2,3);
return 0;
}