Change This is not a solution. it is more deceiving. But I think he is doing what is needed.
#define INVOKE(hof, func, arg) \ hof([](const decltype(arg)& arg_){return func(arg_);}, arg)
Example:
// This function mimics the signature of QtCollector::run for testing template <typename Functor, typename Arg1> auto QtConcurrent_run(Functor functor, const Arg1 &arg1) -> decltype(functor(arg1)) { return functor(arg1); }
Take a look here at ideone.
The original answer follows for historical purposes and some explanation.
Just for clarity, because this is an interesting question, but perhaps more important for you to keep your project moving, there is a reason why you donβt just want to transfer various function overrides to a functor structure and pass the functor structure directly to QtConcurrent :: run who would gladly accept such a thing?
If all function definitions were in the same class, then there would be no problem:
struct f_collector { ReturnType1 f(ArgType1 arg); ReturnType2 f(ArgType2 arg); ReturnType3 f(ArgType3 arg);
Then you can call QtConcurrent::run(f_collector(), argument) , and it will just work (unless you need a perfect redirect, but this is a trifle).
So I had the following idea, which was to build a functor similar to the above on the fly, which basically means giving it a lambda expression. The lambda itself is quite simple; It's easy enough to make a macro out of it:
But then I remembered that lambda, along with its other virtues, can be automatically converted to function pointers if they don't have captures. And this lambda has no captures, because the function itself is the only external symbol, and it is not an object with an automatic storage class. So, I think in the bottom line you can do this with a small template:
#define INVOKE(hof, func, arg) \ hof([](const decltype(arg)& arg_){return func(arg_);}, arg);