title: C++ Overloading Macros
body: <p>I saw different solutions and workarounds of overloading macros. But I seem to have difficulties on this one.<br>
  I have a <code>PRINT_DEBUG</code> macro that prints to the visual studio debugger:</p>
  
  <pre><code>#define DEBUG_PRINT(message, ...)   _RPTN(0, message "\n", __VA_ARGS__)
  </code></pre>
  
  <p>Now say i want to overload it like so:</p>
  
  <pre><code>#define DEBUG_PRINT(message)        _RPT0(0, message "\n")
  #define DEBUG_PRINT(message, ...)   _RPTN(0, message "\n", __VA_ARGS__)
  </code></pre>
  
  <p>This of course won't work, as it would pick up the first macro.<br>
  So I checked other topics and found this <a href="https://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments">solution</a> and here is what I came up with:</p>
  
  <pre><code>#define PRINT_DEBUG(...) _DEBUG_PRINT_SELECT(__VA_ARGS__, _DEBUG_PRINT2, _DEBUG_PRINT1, ...) (__VA_ARGS__)
  
  #define _DEBUG_PRINT_SELECT(_1, _2, NAME, ...) NAME
  
  #define _DEBUG_PRINT1(message)      _RPT0(0, message "\n")
  #define _DEBUG_PRINT2(message, ...) _RPTN(0, message "\n", __VA_ARGS__)
  </code></pre>
  
  <p>I'm trying to use it like so:</p>
  
  <pre><code>PRINT_DEBUG("My message");
  PRINT_DEBUG("My message %s", someString);
  PRINT_DEBUG("My message %s %d", someString, someValue);
  </code></pre>
  
  <p>Do I really have to hard code each one depending on the amount of arguments I have? or is there any creative way of doing this? <br></p>
  
  <p>The only work around I found, is to just have a single:</p>
  
  <pre><code>#define PRINT_DEBUG(message, ...)   _RPTN(0, message "\n", __VA_ARGS__);
  </code></pre>
  
  <p>And say I want to print just a message, I have to pass a second parameter in mvsc compilers:</p>
  
  <pre><code>PRINT_DEBUG("My message", NULL);
  </code></pre>
  
  <p>Any help would be much appreciated! Thanks in advance!</p>