I have a template function like
template<typename T> T ABS(const T& DiIN){
return (0 > DiIN) ? T(DiIN * (-1)) : T((DiIN));
}
template<typename T> T ADD(const T DiIN1, const T DiIN2) {
return DiIN1 + DiIN2;
}
I need to call the function ABS and/or ADD using a single function pointer. Currently I use two different function pointer names, but found it is getting complicated when I include more template function with different argument length.
my current implementation is like
template<typename T>
struct test {
std::string funcName;
T(funcptr1 *)(T);
T(funcptr2 *)(T, T);
};
test<int> ltest[] = { {"ABS", ABS, NULL}, {"ADD", NULL, ADD} };
Is there a way to
1) Use a single function pointer
2) get rid of the initialization test<int> and use test<T> so that I can use any variable type during runtime?
I am looking for a simple initialization like
template<> //template<typename T>
test<T> ltest[] = = { {"ABS", ABS}, {"ADD", ADD}, ..... };