(这个问题源自这个答案)
我正在尝试调整一个蹦床函数,该函数当前仅传递可变数量的参数。
我想让它转换任何参数PyObject* pyob
to Object{pyob}
,但转发所有其他参数。
So (void* self, int, PyObject*, float)
-> (int, Object, float)
在该示例中,第一个self
论证被剥夺了。这种事总是会发生。在其余参数中,其中一个参数的类型为PyObject*
,因此需要转换为 Object。
这是函数:
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);
}
}
};
它似乎不是转发参数。我认为它正在复制每个论点。我试过了:
call(void* s, Args&&... args)
但这只会产生编译器错误。
完整的测试用例是here
如何修复函数以完美转发除类型之外的所有参数PyObject*
,它应该转换哪个?