c++17方案
c++14方案
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
void f(int a, double b, void* c)
{
std::cout << a << ":" << b << ":" << c << std::endl;
}
template
auto call(Function f, Tuple t, std::index_sequence)
{
return f(std::get(t) ...);
}
template
auto call(Function f, Tuple t)
{
static constexpr auto size = std::tuple_size::value;
return call(f, t, std::make_index_sequence{});
}
int main()
{
std::tuple t;
call(f, t);
}
来源参考
https://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer