fork(3) download
  1. #include <iostream>
  2.  
  3. template<typename R, typename... Args>
  4. auto foo( R (*bar)(Args...), Args... args)
  5. {
  6. return bar(std::forward<Args>(args)...);
  7. }
  8.  
  9. int main()
  10. {
  11. /*
  12.   * mismatched types ‘void (*)(Args ...)’ and ‘main()::<lambda(int, float)>’
  13.   *
  14.   foo([](int x, float y)
  15.   {
  16.   std::cout << x << " " << y << std::endl;
  17.   },
  18.   5, 42.42f
  19.   );
  20.   */
  21.  
  22. foo(+[](int x, float y)
  23. {
  24. std::cout << x << " " << y << std::endl;
  25. },
  26. 5, 42.42f
  27. );
  28.  
  29. foo(+[](int x)
  30. {
  31. std::cout << x << std::endl;
  32. return x;
  33. },
  34. 100500
  35. );
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
5 42.42
100500