title: How to define a macro that defines a function that calls itself?
body: <p>I want to make a macro that will define a function that calls that function on a list of objects. It doesn't necessarily have to be a preprocessor macro, but it should work.</p>
  <p>I want to write something like this:</p>
  <pre><code>CALL_ON_ALL(doSomething(int arg1, bool arg2))
  </code></pre>
  <p>And I want it to produce this:</p>
  <pre><code>void doSomething(int arg1, bool arg2) {
      for (int i = 0; i &lt; delegates.size(); i++)
          delegates[i]-&gt;doSomething(arg1, arg2);
  }
  </code></pre>
  <hr />
  <p>I have something that works:</p>
  <pre><code>#define CALL_ON_ALL(defSig, callSig) \
  void defSig { \
      for (int i = 0; i &lt; delegates.size(); i++) \
          delegates[i]-&gt;callSig; \
  }
  </code></pre>
  <p>The problem is that I have to write the definition signature and the call signature separately like this:</p>
  <pre><code>CALL_ON_ALL(doSomething(int arg1, bool arg2), doSomething(arg1, arg2))
  </code></pre>
  <p>Is there a better way to do this?</p>
  <h2>EDIT</h2>
  <p>It doesn't necessarily have to be a preprocessor macro. Anything that works will do.</p>