我需要在解包和转换参数列表时获取参数的索引。有没有以下问题的解决方案:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void test(int a, std::string b, bool c)
{
cout << a << "," << b << "," << c << endl ;
}
template <typename... ARG>
static void call_test(const vector<void*> ¶ms)
{
test(*static_cast<ARG*>(params[ indexOf(ARG) ])...);
}
int main(int argc, char **argv)
{
int a = 1;
string b = "string";
bool c = false;
vector<void*> v(3);
v[0] = &a;
v[1] = &b;
v[2] = &c;
call_test<int,string,bool>(v);
}
Run Code Online (Sandbox Code Playgroud)