title: Macro overloading
body: <p>Is it possible to define something like this:</p>
  <pre><code>#define FOO(x, y) BAR()
  #define FOO(x, sth, y) BAR(sth)
  </code></pre>
  <p>so that this:</p>
  <pre><code>FOO(&quot;daf&quot;, sfdas);
  FOO(&quot;fdsfs&quot;, something, 5);
  </code></pre>
  <p>is translated to this:</p>
  <pre><code>BAR();
  BAR(something);
  </code></pre>
  <p>?</p>
  <p>Edit:
  Actually, <code>BAR</code>'s are methods of my class. Sorry for not saying that before (didn't think it was relevant).</p>
  <p>Answering DyP's question:</p>
  <pre><code>class Testy
  {
      public:
      void TestFunction(std::string one, std::string two, std::string three)
      {
          std::cout &lt;&lt; one &lt;&lt; two &lt;&lt; three;
      }
      void AnotherOne(std::string one)
      {
          std::cout &lt;&lt; one;
      }
      void AnotherOne(void)
      {
          std::cout &lt;&lt; &quot;&quot;;
      }
  };
  
  #define PP_NARG(...) PP_NARG_(__VA_ARGS__,PP_RSEQ_N())
  #define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
  #define PP_ARG_N(_1, _2, _3, N, ...) N
  #define PP_RSEQ_N() 3, 2, 1, 0
  
  // macro for exactly 2 arguments
  #define FOO_2(_1, _2) AnotherOne()
  // macro for exactly 3 arguments
  #define FOO_3(_1, _2, _3) AnotherOne(_2)
  
  // macro selection by number of arguments
  #define FOO_(N) FOO_##N
  #define FOO_EVAL(N) FOO_(N)
  #define TestFunction(...) FOO_EVAL(PP_NARG(__VA_ARGS__))(__VA_ARGS__)
  </code></pre>
  <p>And call:</p>
  <pre><code>Testy testy;
  testy.TestFunction(&quot;one&quot;, &quot;two&quot;, &quot;three&quot;);   // line 9
  </code></pre>
  <p>Compiler output:</p>
  <blockquote>
  <p>Warning   1   warning C4003: not enough actual parameters for macro 'PP_ARG_N'    main.cpp    9</p>
  <p>Warning   2   warning C4003: not enough actual parameters for macro 'FOO_'    main.cpp    9</p>
  <p>Error 3   error C2039: 'FOO_' : is not a member of 'Testy'    main.cpp    9</p>
  </blockquote>