title: How to detect that macro is already used in current scope?
body: <p>I would like to make a macro-like object that can detect its use in the current scope and behave differently in such a case. For example, consider the following fragment of code</p>
  <pre><code>#define FOO /* expand to printf(&quot;first time\n&quot;); or printf(&quot;not a first time\n&quot;); */
  
  {
     FOO // prints &quot;first time&quot;
  
     FOO // prints &quot;not a first time&quot;
  
     {
         FOO // prints &quot;first time&quot;
  
         FOO // prints &quot;not a first time&quot;
     }
  
     FOO // prints &quot;not a first time&quot;
  }
  </code></pre>
  <p>Is it possible to make this with macro or any other language element in C++?</p>
  <hr />
  <p>For people curious why I need this: I would like to make an easily copy-pastable macro FOO that I can put everywhere to get time spent in code fragment between two occurrences of it.</p>
  <p>For example:</p>
  <pre><code>FOO // initialize timer
  // code fragment 1
  FOO // print the time spent in code fragment 1
  // code fragment 2
  FOO // print the time spent in code fragment 2
  // code fragment 3
  FOO // print the time spent in code fragment 3
  </code></pre>