c++ 可变参数的打包到tuple,使用tuple传递参数


	c++ 可变参数的打包到tuple,使用tuple传递参数
[编程语言教程]

直接上代码

 

void Add(int a, double b, short c, const char * f) {
	std::cout << f << a << ", " << b << ", " << c << ";
";
}

void *p = nullptr;

template <typename ... Args>
void CallLater(Args... args) {
    
	auto c = std::make_tuple(args...);
	auto ptuple = new decltype(c);
	*ptuple = c;
	p = (void *)ptuple;
	

}

void doCall(){
    using v = std::tuple<int , double , short , const char * >;
    v * ptuple = static_cast<v *>(p);
    std::apply(Add, *ptuple);
    delete ptuple;
    p = nullptr;
}

void main()
{
    CallLater(1, 3.5, (short)3, "this");
    doCall();
}
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » c++ 可变参数的打包到tuple,使用tuple传递参数