“解压缩”元组以调用匹配的函数指针
std::tuple
#include <iostream>#include <tuple>void f(int a, double b, void* c) { std::cout << a << ":" << b << ":" << c << std::endl;}template <typename ...Args>struct save_it_for_later { std::tuple<Args...> params; void (*func)(Args...); void delayed_dispatch() { // How can I "unpack" params to call func? func(std::get<0>(params), std::get<1>(params), std::get<2>(params)); // But I *really* don't want to write 20 versions of dispatch so I'd rather // write something like: func(params...); // Not legal }};int main() { int a=666; double b = -1.234; void *c = NULL; save_it_for_later<int,double,void*> saved = { std::tuple<int,double,void*>(a,b,c), f}; saved.delayed_dispatch();}
std::tuple
template <typename Head, typename ...Tail>
std::bind
std::tuple
拉莫斯之舞
守着星空守着你