title: How to force specific type in C++ preprocessor macro?
body: <p>I'm trying to generate a static variable via a preprocessor macro for logging purposes. The variable serves as a counter how often a specific message as been sent already. in order to make this thread-safe I wanted to switch from using an <code>int</code> counter to <code>std::atomic&lt;int&gt;</code> - which works fine on most compilers:</p>
  <pre class="lang-cpp prettyprint-override"><code>#define GENERATE_LOG_VAR(Count) static std::atomic&lt;int&gt; local___FUNCTION__##Count##__LINE__ = std::atomic&lt;int&gt;(Count)
  #define GET_LOG_VARIABLE(Count) local___FUNCTION__##Count##__LINE__
  </code></pre>
  <p>However, on GCC 7.3.1 I get the following error:</p>
  <pre><code>error: use of deleted function 'std::atomic&lt;int&gt;::atomic(const std::atomic&lt;int&gt;&amp;)'
   #define GENERATE_LOG_VAR(Count) static std::atomic&lt;int&gt; local___FUNCTION__##Count##__LINE__ = std::atomic&lt;int&gt;(Count)
                                                                                                                       ^
  note: in expansion of macro 'GENERATE_LOG_VAR'
       GENERATE_LOG_VAR(max_log_count);                                                                                        \
       ^~~~~~~~~~~~~~~~
  
  note: declared here
         atomic(const atomic&amp;) = delete;
         ^~~~~~
  </code></pre>
  <p>So I understand that the compiler somehow interprets <code>Count</code> as <code>std::atomic&lt;int&gt;</code> and tries to call the copy constructor which seems to be deleted. But how can I circumvent this problem?</p>
  <p>I have already tried simply assigning <code>Count</code> with very similar results:</p>
  <pre><code>error: use of deleted function 'std::atomic&lt;int&gt;::atomic(const std::atomic&lt;int&gt;&amp;)'
   #define GENERATE_ONCE GENERATE_LOG_VAR(1)
                                        ^
  note: in definition of macro 'GENERATE_LOG_VAR'
   #define GENERATE_LOG_VAR(Count) static std::atomic&lt;int&gt; local___FUNCTION__##Count##__LINE__ = Count
                                                                                                    ^~~~~
  note: declared here
         atomic(const atomic&amp;) = delete;
         ^~~~~~
  note:   after user-defined conversion: constexpr std::atomic&lt;int&gt;::atomic(std::atomic&lt;int&gt;::__integral_type)
         constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
                   ^~~~~~
  </code></pre>
  <p>So my question is either</p>
  <ul>
  <li>how can I force the compiler to interpret <code>Count</code> as <code>int</code>? or</li>
  <li>how can I solve this otherwise?</li>
  </ul>