title: "Backporting" nullptr to C++-pre-C++0x programs
body: <p>More or less what the title suggests. While I'm <a href="https://stackoverflow.com/questions/1754397/how-are-you-using-c11-today/8051442#8051442">not yet using C++0x</a> I'd like to be prepared for when it happens, and I'd also like to reduce the amount of code I have to rewrite to use some of its facilities. That way I can get backwards and forwards compatibility in one go. </p>
  
  <p>One of the most interesting ones I have found is <a href="https://stackoverflow.com/questions/1282295/what-exactly-is-nullptr-in-c0x"><code>nullptr</code></a>, which I've been using more often recently. </p>
  
  <p>After checking the "Official workaround" and <a href="http://en.wikibooks.org/wiki/More_C++_Idioms/nullptr#Solution_and_Sample_Code" rel="nofollow noreferrer">Meyer's suggestion</a>, I decided that I'd like to use this in both my C++ and future C++0x programs. The second part is simple -- being a keyword, <code>nullptr</code> will simply be supported. But the first part is causing me some discomfort.</p>
  
  <p>The Meyers proposal functions like this:</p>
  
  <pre><code>class nullptr_t { // ← this is my issue
      // definition of nullptr_t
  } nullptr = { };
  </code></pre>
  
  <p>The problem with that proposal is that it declares the type to be declared as <code>std::nullptr_t</code> as required by C++0x. Which means for the workaround to "feel native" it has to be done by reopening the <code>std::</code> namespace to add a type. <strong>I have the understanding that is illegal to do in a C++ program</strong> (unlike adding <em>specializations</em> which is apparently frown-and-let-go-with-a-warning). </p>
  
  <p>I want to use <code>nullptr</code> in a comfortable <strong>AND</strong> legal way in a C++ program. One option I had thought of was declaring the type in another namespace and then bring it in using <code>using</code>:</p>
  
  <pre><code>namespace mylibrary {
  class nullptr_t {
      ....
  } nullptr = { };
  // end namespace
  }
  
  // These would have to go in the header file.
  using mylibrary::nullptr;
  using mylibrary::nullptr_t; // apparently this is necessary as well?
  </code></pre>
  
  <p>Would this be the correct way to make it work? It would force <code>using</code>directives, which also forces a specific order of <code>#include</code> directives as well. Would I be right to expect that no pre-C++0x code would request  the type <code>nullptr_t</code> with namespace (as a function argument type, for example)? Would it actually work "feeling native" if it is done this way?</p>
  
  <hr>
  
  <p>As an addendum, is it a welcomed or frowned upon thing to try and backport some nifty C++0x things to C++ for better compatibility and coding? In the meantime I have integrated this solution and other ones I'm working on <a href="http://ryan.gulix.cl/fossil.cgi/cxxomfort" rel="nofollow noreferrer">in a piece of software to be released</a>.</p>