dimanche 3 mai 2020

How to template a parameter in function pointer?

I have a template:

template<typename T>
void testFuction(int(*testFunc)(CallBack, void *, T *))
{
    // define CallBack callback, void* param1, T* param2
    // ...
    testFunc(callback, param1, param2);
}

It works but it looks terrible, I want to do something like:

template<typename T>
// using TestFunc<T> = std::function<int(CallBack, void *, T *)>
void testFuction(TestFunc<T> testFunc)
{
   // define CallBack callback, void* param1, T* param2
   // ...
   testFunc(callback, param1, param2);
}

But it doesn't work.

Can somebody help me with it? I also overload many similar functions like that with some added parameters and they look ugly. I want to define TestFunc<T> once and use it again in the template functions.

Aucun commentaire:

Enregistrer un commentaire