fork download
  1. #define INVOKE(hof, func, arg) \
  2.   hof([](const decltype(arg)& arg_){return func(arg_);}, arg);
  3.  
  4. // This function mimics the signature of QtCollector::run for testing
  5. template <typename Functor, typename Arg1>
  6. auto QtConcurrent_run(Functor functor, const Arg1 &arg1)
  7. -> decltype(functor(arg1))
  8. {
  9. return functor(arg1);
  10. }
  11.  
  12. #include <iostream>
  13.  
  14. int f(int x) { std::cout << "int" << " " << x << std::endl; return x; }
  15. double f(double x) { std::cout << "double" << " " << x << std::endl; return x; }
  16.  
  17. int main() {
  18. INVOKE(QtConcurrent_run, f, 3);
  19. INVOKE(QtConcurrent_run, f, 3.14);
  20. INVOKE(QtConcurrent_run, f, '3');
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
int 3
double 3.14
int 51