title: Uniquely identifiable call to a macro
body: <h1>The context</h1>
  
  <p>I am trying to implement an easy to use <code>async/await</code> pattern in my C++ code, and I have a way of doing it that I find remarkably simple to use. However, since I am using macros, it also comes at a cost in terms of weakness against exotic code.</p>
  
  <p>Here is the idea:</p>
  
  <ul>
  <li>We wrap the execution context in a class, whose members are the variables used by the <code>async</code> function.</li>
  <li><p>Inside the body of the <code>async</code> function I implement with macros a switch on a member <code>entrypoint</code> that I use to keep track where jump to when the execution of the function is resumed:</p>
  
  <pre><code>switch(this-&gt;entrypoint)
  {
      // All the async code occurs here, like:
      await(this-&gt;foo = bar());
      std :: cout &lt;&lt; this-&gt;foo &lt;&lt; std :: endl;
      await(this-&gt;foo2 = bar2());
      std :: cout &lt;&lt; this-&gt;foo2 &lt;&lt; std :: endl;
  }
  </code></pre></li>
  <li><p>The <code>await(assignment)</code> macro actually defines something in the form:</p>
  
  <pre><code>this-&gt;entrypoint = (some value x);
  return;
  case x:
  </code></pre></li>
  </ul>
  
  <p>Now, this is obviously less compact than a full-fledged <code>async function</code> we could have, for example, in Javascript, but it is more than enough for my needs. Also this prevents nested switches (which I use very rarely) and you cannot define variables locally unless you wrap them somehow in a <code>{ /*..*/ }</code>. But I get a super compact way of doing asynchronous operations with a synchronous style.</p>
  
  <p><strong>Remark</strong>: The downsides and weaknesses of this strategy are quite clear to me, this is not the point of my question, I just added this to help understand what I need.</p>
  
  <h1>The question</h1>
  
  <p>The above compiles and runs nicely. However, I am having a serious problem: in the <code>await</code> macro, I need to generate some unique value <code>x</code> to use in the <code>case</code> statement. So far, I am doing it using <code>__LINE__</code>, which works nicely and prevents collisions for most practical purposes. What happens, however, when you write two <code>await</code> statements on the same line?</p>
  
  <p>So I wonder: is there a better way than using <code>__LINE__</code> to uniquely identify a call to a macro, so that whenever I call the same macro from two distinct places in my code I get different values expanded?</p>