(This question follows from this answer)
I am trying to adapt a trampoline function that is currently just passing through a variable number of arguments.
I would like to have it convert any argument PyObject* pyob
to Object{pyob}
, but forward all other arguments through.
So (void* self, int, PyObject*, float)
-> (int, Object, float)
In that example, the first self
argument is stripped away. This always happens. Out of the remaining arguments, one of them is of type PyObject*
, and hence requires conversion to Object.
Here is the function:
template <typename T, T t>
struct trap;
template <typename R, typename... Args, R(Base::*t)(Args...)>
struct trap<R(Base::*)(Args...), t>
{
static R
call(void* s, Args... args)
{
std::cout << "trap:" << typeid(t).name() << std::endl;
try
{
return (get_base(s)->*t)(std::forward<Args>(args)...);
}
catch (...)
{
std::cout << "CAUGHT" << std::endl;
return std::is_integral<R>::value ? static_cast<R>(-42) : static_cast<R>(-3.14);
}
}
};
It appears not to be forwarding arguments. I think it is making a copy of each argument. I've tried:
call(void* s, Args&&... args)
But that just generates compiler errors.
The complete test case is here
How can I fix the function to perfect-forward all arguments apart from those of type PyObject*
, which it should convert?