0

In Herb Sutter's cppcon talk, he stated (again) that they have ambitions to get rid of macros entirely and replace it with modern C++ stuff.

I am using the following macro for logging in printf-style (will most likely change to fmtlib, though) and I am wondering, how to get rid of macros in that case.

#define LOG_INFO(...)       do { printf("INFO:    "); printf(__VA_ARGS__); printf(" | file[%s] line[%d]\n", __FILE__, __LINE__); } while(0)

I don't see how this could be done without macros because of __FILE__ and __LINE__ alone. But I'm also not aware of any replacement for __VA_ARGS__. Does such a thing exist?

jaggedSpire
  • 4,423
  • 2
  • 26
  • 52
j00hi
  • 5,420
  • 3
  • 45
  • 82
  • 3
    Variadic templates? As to `__FILE__` and `__LINE__`, you are looking for `source_location`. – T.C. Dec 08 '18 at 09:22
  • You are looking at the wrong part: I'm not aware of any proposal adding a replacement for token-pasting (`##`) and stringizing (`#`), or general token-handling, like needed for example in [tag:x-macros], or for generating many blobs of source. – Deduplicator Dec 08 '18 at 10:13
  • you can write function `void LogInfo(PCSTR file, ULONG line, PCSTR format, ...)` and use macro `#define LOG_INFO(...) LogInfo(__FILE__, __LINE__, __VA_ARGS__)` – RbMm Dec 08 '18 at 10:28
  • @Deduplicator: "*I'm not aware of any proposal adding a replacement for token-pasting (##) and stringizing (#), or general token-handling, like needed for example in x-macros, or for generating many blobs of source.*" Find any proposal about generative reflection and/or metaclasses, coupled with compile-time string manipulation (which C++20 already has). Now, that's not a general replacement for *all* such macro uses, but if it covers 99% of the cases where a library exposes a macro as part of the library's interface, isn't that good enough? – Nicol Bolas Dec 08 '18 at 14:38
  • 1
    Possible duplicate of [How to make a variadic macro for std::cout?](https://stackoverflow.com/questions/29326460/how-to-make-a-variadic-macro-for-stdcout) – Mike Kinghan Dec 13 '18 at 07:40

0 Answers0