fork download
  1. #include <iostream>
  2.  
  3. int function (int arg) { return arg; }
  4. typedef int (*function_t) (int arg);
  5.  
  6. template <typename T_ret, typename... T_args>
  7. class caller {
  8. T_ret (*m_p) (T_args... args);
  9. public:
  10. T_ret call (T_args... args) {
  11. return m_p(args...);
  12. }
  13. caller (T_ret (*p)(T_args...args)) : m_p(p) {}
  14. };
  15.  
  16. template <typename T_ret, typename... T_args>
  17. caller<T_ret, T_args...> get_caller(T_ret(*prototype)(T_args...))
  18. {
  19. return caller<T_ret, T_args...>(prototype);
  20. }
  21.  
  22. int main()
  23. {
  24. function_t f = &function;
  25. auto c = get_caller(f);
  26. std::cout << c.call(1) << std::endl;
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 3344KB
stdin
Standard input is empty
stdout
1