This question already has an answer here:
- Variadic templates 8 answers
Using the following class, I would like to be able to create an instance of a specified Foo()
to store and call a function, but how can I transmit the necessary arguments to a function call
?
template<class R, class... Args> class Foo {
std::function<R(Args...)> func;
Foo(const std::function<R(Args...)> &funcIn) : func(funcIn) {}
R call(Args...) {
return func(/* ? */);
}
};
E.g:
int main() {
typedef typename Foo<int(int)> Bar;
Bar x([](int y, int z){return y + z + 2;});
std::cout << x.call(12, 7);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire