title: No type named 'unique_ptr' in namespace 'std' when compiling under LLVM/Clang
body: <p>I'm catching a compile error when attempting to use <code>unique_ptr</code> on Apple platforms with <code>-std=c++11</code>:</p>
  
  <pre><code>$ make
  c++ -std=c++11 -DNDEBUG -g2 -O3 -fPIC -march=native -Wall -Wextra -pipe -c 3way.cpp
  In file included ...
  ./smartptr.h:23:27: error: no type named 'unique_ptr' in namespace 'std'
      using auto_ptr = std::unique_ptr&lt;T&gt;;
                       ~~~~~^
  ./smartptr.h:23:37: error: expected ';' after alias declaration
      using auto_ptr = std::unique_ptr&lt;T&gt;;
  </code></pre>
  
  <p>According to Marshall Clow, who I consider an expert on the <a href="http://marshall.calepin.co/c-and-xcode-46.html" rel="noreferrer">C++ Standard Library with Clang and Apple</a>:</p>
  
  <blockquote>
    <p>Technical Report #1 (TR1) was a set of library additions to the C++03
    standard. Representing the fact that they were not part of the
    "official" standard, they were placed in the namespace std::tr1.</p>
    
    <p>In c++11, they are officially part of the standard, and live in the
    namespace std, just like vector and string. The include files no
    longer live in the "tr1" folder, either.</p>
  </blockquote>
  
  <p>Take aways:</p>
  
  <ul>
  <li>Apple and C++03 = use TR1 namespace</li>
  <li>Apple and C++11 = use STD namespace</li>
  <li>Use <code>LIBCPP_VERSION</code> to detect <code>libc++</code></li>
  </ul>
  
  <p>Now, here's what I have in <code>smartptr.h</code>:</p>
  
  <pre><code>#include &lt;memory&gt;
  
  // Manage auto_ptr warnings and deprecation in C++11
  // Microsoft added template aliases to VS2015
  #if (__cplusplus &gt;= 201103L) || (_MSC_VER &gt;= 1900)
    template&lt;typename T&gt;
      using auto_ptr = std::unique_ptr&lt;T&gt;;
  #else
    using std::auto_ptr;
  #endif // C++11
  </code></pre>
  
  <p>I think the last thing to check is the <code>__APPLE__</code> define, and here it is:</p>
  
  <pre><code>$ c++ -x c++ -dM -E - &lt; /dev/null | grep -i apple
  #define __APPLE_CC__ 6000
  #define __APPLE__ 1
  #define __VERSION__ "4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)"
  #define __apple_build_version__ 5030040
  </code></pre>
  
  <p>Why am I receiving a <strong><em><code>error: no type named 'unique_ptr' in namespace 'std'</code></em></strong> when using <code>-std=c++11</code>?</p>
  
  <hr>
  
  <p>I think these are the four test cases. It attempts to exercise the four configurations from the cross product of: {C++03,C++11} x {libc++,libstdc++}.</p>
  
  <ul>
  <li>c++ -c test-clapple.cxx
  
  <ul>
  <li>OK</li>
  </ul></li>
  <li>c++ -stdlib=libc++ -c test-clapple.cxx
  
  <ul>
  <li>OK</li>
  </ul></li>
  <li>c++ -std=c++11 -c test-clapple.cxx
  
  <ul>
  <li>FAIL</li>
  </ul></li>
  <li>c++ -std=c++11 -stdlib=libc++ -c test-clapple.cxx
  
  <ul>
  <li>OK</li>
  </ul></li>
  </ul>
  
  <p>Here is the test driver. Be sure to test it on OS X so you get the full effects of the TR1 namespace in 2015.</p>
  
  <pre><code>$ cat test-clapple.cxx
  
  // c++ -c test-clapple.cxx
  // c++ -stdlib=libc++ -c test-clapple.cxx
  // c++ -std=c++11 -c test-clapple.cxx
  // c++ -std=c++11 -stdlib=libc++ -c test-clapple.cxx
  
  #include &lt;memory&gt;
  
  // Manage auto_ptr warnings and deprecation in C++11
  #if (__cplusplus &gt;= 201103L) || (_MSC_VER &gt;= 1900)
    template&lt;typename T&gt;
      using auto_ptr = std::unique_ptr&lt;T&gt;;
  #else
      using std::auto_ptr;
  #endif // C++11
  
  int main(int argc, char* argv[])
  {
      return argc;
  }
  </code></pre>