Is there any way in c++11/14 to write variadic template function like this:
template <typename ReturnType, typename Args...>
std::function<ReturnType()> bindArgumentsFromTuple
(std::function<ReturnType(Args... args)> f,
const std::tuple<Args...>& t)
that binds elements of tuple t to function f as arguments (such that the number of elements and its types are identical in function arguments and tuple)?
Example of usage:
void dummy_print(int i, double d)
{
std::cout << i << "," << d << '\n';
}
void dummy_print2(int i, double d, std::string& s)
{
std::cout << i << "," << d << "," << s << '\n';
}
int main() {
std::tuple<int,double> t(77,1.1);
std::tuple<int,double,std::string> t2(1,2.0,"aaa");
auto f1 = bindArgumentsFromTuple(dummy_print, t);
f1();
auto f2 = bindArgumentsFromTuple(dummy_print2, t2);
f2();
return 0;
}