I have this simple C++ template function. I need to pass any number of arguments of any type to the Method, as shown below. How do I do this?
template <typename T1, typename T2, auto Method>
T1 * wrapObject()
{
T2 * obj = (*_asposeObj.*Method)(// I would like to pass arguments here);
...
}
This is a C++20 project, compiler is g++.
I tried:
template <typename T1, typename T2, auto Method, auto ...Args>
T1 * wrapObject(Args... args)
{
T2 * obj = (*_asposeObj.*Method)(&args);
...
}
But this won't compile. Any ideas?
EDIT:
Thanks for all the help, it works now!
However, there is another related problem: What if there are two versions of Method in asposeObj? Like:
asposeObj->idx_get(int index);
asposeObj->idx_get(someObj);
The compiler doesn't seem to be able to figure our which one to call and I'm getting "unable to deduce ‘auto’ from ..." errors.
How to modify the following call to make this work? wrapObject is the template function I mentioned above.
wrapObject<SomeClass, AnotherClass, &ClassAsposeOj::idx_get>(index)