fork download
  1. #include <iostream>
  2. #include <utility>
  3. using namespace std;
  4.  
  5. template <class T>
  6. void PrintArgs(const T &a1){
  7. cout << a1 << endl;
  8. }
  9.  
  10. template <class T, class ...ARGS>
  11. void PrintArgs(const T &a1,const ARGS& ...args){
  12. cout << a1 << ",";
  13. PrintArgs(args...);
  14. }
  15.  
  16. template <class F,class ...ARGS>
  17. auto LogFunc(const char *fname,F func,ARGS &&... args)
  18. ->decltype(func(std::forward<ARGS>(args)...)){
  19. cout << fname << ":";
  20. PrintArgs(args...);
  21. return func(std::forward<ARGS>(args)...);
  22. }
  23.  
  24. #define LOG_CALL(func,...) LogFunc(#func,func,__VA_ARGS__)
  25.  
  26. void foo(int a,double b, char c){
  27.  
  28. }
  29.  
  30. int main() {
  31.  
  32. LOG_CALL(foo,1,2.0,'c');
  33.  
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
foo:1,2,c