#include <iostream>
void padd(int a, int b) { std::cout << a + b << std::endl; }
void psub(int a, int b) { std::cout << a - b << std::endl; }
template <??? op>
class Foo {
public:
template<typename... Arguments>
void execute(Arguments... args) {
op(args ...);
}
};
int main() {
auto f1 = Foo<padd>();
f1.execute(5, 6); // ideally would print 11
auto f2 = Foo<psub>();
f2.execute(5, 6); // ideally would print -1
return 0;
}
I am trying to figure out how to bind functions (and, if possible, template functions) as template parameters in C++.
As it stands I am not aware if this is possible.
A kicker here is that the function signatures are not guaranteed to be similar.
edit: thanks to @sehe and @Potatoswatter, my current solution is thus: http://ideone.com/0jcbUi. Will write up answer when appropriate.