No type named 'unique_ptr' im Namespace 'std' beim Kompilieren unter LLVM / Clang
Beim Versuch, @ zu verwenden, ist ein Kompilierungsfehler aufgetreteunique_ptr
auf Apple-Plattformen mit-std=c++11
:
$ 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<T>;
~~~~~^
./smartptr.h:23:37: error: expected ';' after alias declaration
using auto_ptr = std::unique_ptr<T>;
Nach Angaben von Marshall Clow, den ich als Experten für die C ++ Standard Library mit Clang und Apple:
Technical Report # 1 (TR1) war eine Reihe von Bibliothekserweiterungen zum C ++ 03-Standard. Sie stellten die Tatsache dar, dass sie nicht Teil des "offiziellen" Standards waren, und wurden in den Namespace std :: tr1 gestellt.
n c ++ 11 sind sie offiziell Teil des Standards und befinden sich im Namespace std, genau wie vector und string. Die Include-Dateien befinden sich ebenfalls nicht mehr im Ordner "tr1".
Take aways:
Apple und C ++ 03 = TR1-Namespace verwendenApple und C ++ 11 = STD-Namespace verwendenVerwendenLIBCPP_VERSION
zu erkennenlibc++
Now, hier ist was ich in @ hasmartptr.h
:
#include <memory>
// Manage auto_ptr warnings and deprecation in C++11
// Microsoft added template aliases to VS2015
#if (__cplusplus >= 201103L) || (_MSC_VER >= 1900)
template<typename T>
using auto_ptr = std::unique_ptr<T>;
#else
using std::auto_ptr;
#endif // C++11
Ich denke, das Letzte, was überprüft werden muss, ist das__APPLE__
define, und hier ist es:
$ c++ -x c++ -dM -E - < /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
Warum erhalte ich einerror: no type named 'unique_ptr' in namespace 'std'
beim Benutzen-std=c++11
?
Ich denke, das sind die vier Testfälle. Es wird versucht, die vier Konfigurationen aus dem Kreuzprodukt von {C ++ 03, C ++ 11} x {libc ++, libstdc ++} zu üben.
c ++ -c test-clapple.cxxIN ORDNUN c ++ -stdlib = libc ++ -c test-clapple.cxxIN ORDNUN c ++ -std = c ++ 11 -c test-clapple.cxxSCHEITER c ++ -std = c ++ 11 -stdlib = libc ++ -c test-clapple.cxxIN ORDNUNHier ist der Testfahrer. Testen Sie es unbedingt unter OS X, damit Sie 2015 die vollen Auswirkungen des TR1-Namespace erhalten.
$ 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 <memory>
// Manage auto_ptr warnings and deprecation in C++11
#if (__cplusplus >= 201103L) || (_MSC_VER >= 1900)
template<typename T>
using auto_ptr = std::unique_ptr<T>;
#else
using std::auto_ptr;
#endif // C++11
int main(int argc, char* argv[])
{
return argc;
}