Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #define log_error(...) log_api(__FILE__, __LINE__, log_api_severity::error, /*print_console=*/false, __VA_ARGS__)
  2.  
  3. template<typename ...Args>
  4. std::result_of<Args...>::type tmpl_call_return_f(Args...&& args)
  5. {
  6. return log_api(__FILE__, __LINE__, log_api_severity::error, /*print_console=*/false, std::forward<Args>(args)...);
  7. }
  8.  
  9. #include <iostream>
  10. #include <cstdarg>
  11.  
  12. // This is the macro I want to convert into constexpr variadic template?
  13. #define log_error(...) log_api(__FILE__, __LINE__, log_api_severity::error, /*print_console=*/false, __VA_ARGS__)
  14.  
  15. // Error: use the 'typename' keyword to treat nontype "std::result_of<_Fty>::type[with _Fty=Args...]" as a type in a dependent context
  16. // template<typename ...Args>
  17. // std::result_of<Args...>::type tmpl_call_return_f(Args...&& args)
  18. // {
  19. // return log_api(__FILE__, __LINE__, log_api_severity::error, /*print_console=*/false, std::forward<Args>(args)...);
  20. // }
  21.  
  22. // Log severity levels
  23. enum class log_api_severity
  24. {
  25. error = 0,
  26. warning = 50,
  27. info = 51,
  28. debug = 52,
  29. trace = 53,
  30. all = 54,
  31. disabled = 55,
  32. };
  33.  
  34. bool log_api(const char* filename, const int line_number, const log_api_severity severity, const bool print_console, const char* fmt, ...)
  35. {
  36. char msg[1024] = "";
  37. va_list args;
  38. va_start(args, fmt);
  39. vsprintf_s(msg, sizeof(msg), fmt, args);
  40.  
  41. // write in the log file...
  42. printf("%s", msg);
  43.  
  44. va_end(args);
  45. return true;
  46. }
  47.  
  48. int main()
  49. {
  50. log_error("this is an error message");
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement