fork(8) download
  1. #include <iostream>
  2. #include <functional>
  3. #include <utility>
  4.  
  5. void cb1(int a, double b, char c)
  6. {
  7. std::cout << "cb1( " << a << ", " << b << ", " << c << ")\n";
  8. }
  9.  
  10. void cb2(const char* a, const char* b)
  11. {
  12. std::cout << "cb2( \"" << a << "\", \"" << b << "\")\n" ;
  13. }
  14.  
  15. template <typename ...Args>
  16. void mylibfun(int, int, std::function<void(Args...)>&& func, Args... args)
  17. {
  18. func(args...);
  19. }
  20.  
  21. template <typename ...Args>
  22. void mylibfun(int a, int b, void f(Args...), Args... args)
  23. {
  24. mylibfun(a, b, std::function<void(Args...)>(f), args...);
  25. }
  26.  
  27. int main()
  28. {
  29. mylibfun(1, 2, cb1, 1, 2.0, 'c');
  30. mylibfun(3, 4, cb2, "abc", "xyz") ;
  31. }
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
cb1( 1, 2, c)
cb2( "abc", "xyz")