Function as template parameter.
Code:
#include <iostream>
template <typename F, typename D>
D Funcall(F f, D a, D b) {
return f(a, b);
}
template <typename D>
D Add(D a, D b) {
return a + b;
}
template <typename D>
D Sub(D a, D b) {
return a - b;
}
int main() {
std::cout << Funcall(Add<long int>, 3, 4) << std::endl;
std::cout << Funcall(Sub<double>, 5.34, 2.67) << std::endl;
return 0;
}
This piece of code is useless, just want to show the ability of template.