jeudi 8 janvier 2015

Perfect-forward non-T arguments while converting T-s

(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 (myInt, myPyObPtr, myFloat) -> (myInt, Object{myPyObPtr}, myFloat)


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?


Aucun commentaire:

Enregistrer un commentaire