title: C++ Preprocessor metaprogramming: obtaining an unique value?
body: <p>I'm exploiting the behavior of the constructors of C++ global variables to run code at startup in a simple manner. It's a very easy concept but a little difficult to explain so let me just paste the code:</p>
  
  <pre><code>struct _LuaVariableRegistration
  {
      template&lt;class T&gt;
      _LuaVariableRegistration(const char* lua_name, const T&amp; c_name) {
          /* ... This code will be ran at startup; it temporarily saves lua_name and c_name in a std::map and when Lua is loaded it will register all temporarily global variables in Lua. */
      }
  };
  </code></pre>
  
  <p>However manually instantiating that super ugly class every time one wants to register a Lua global variable is cumbersome; that's why I created the following macro:</p>
  
  <pre><code>#define LUA_GLOBAL(lua_name, c_name) static Snow::_LuaVariableRegistration _____LuaGlobal ## c_name (lua_name, c_name);
  </code></pre>
  
  <p>So all you have to do is put that in the global scope of a cpp file and everything works perfectly:</p>
  
  <pre><code>LUA_GLOBAL("LuaIsCool", true);
  </code></pre>
  
  <p>There you go! Now in Lua <code>LuaIsCool</code> will be a variable initialized to true!</p>
  
  <p>But, here is the problem:</p>
  
  <pre><code>LUA_GLOBAL("ACCESS_NONE", Access::None);
  </code></pre>
  
  <p>Which becomes:</p>
  
  <pre><code>static Snow::_LuaVariableRegistration _____LuaGlobalAccess::None ("ACCESS_NONE", &amp;Access::None);
  </code></pre>
  
  <p>:((
  I need to concatenate <code>c_name</code> in the macro or it will complain about two variables with the same name; I tried replacing it with <code>__LINE__</code> but it actually becomes <code>_____LuaGlobalAccess__LINE__</code> (ie it doesn't get replaced).</p>
  
  <p>So, is there a way to somehow obtain an unique string, or any other workaround?</p>
  
  <p>PS: Yes I know names that begin with _ are reserved; I use them anyway for purposes like this being careful to pick names that the standard library is extremely unlikely to ever use. Additionally they are in a namespace.</p>