TR1 is an experiment performed by the C ++ Standards Committee. The purpose of the experiment is to gain field experience for libraries, hoping to standardize them in a future standard.
TR1 is not a regulatory standard.
The TR1 specification indicates the use of the std::tr1
namespace. The reason things were not put in the std
namespace is to allow the committee more freedom to change the TR1 specification on the way to standardization. And yes, modifications were made in those places where most of TR1 was standardized in C ++ 11.
Document TR1 begins with these words:
This technical report is not normative. Some of the library components in this technical report may be considered for standardization in a future version of C ++, but they are not currently part of any C ++ standard. Some of the components of this technical report may never be standardized, and others may be standardized in a substantially modified form.
The purpose of this technical report is to create more widespread existing practices for the C ++ extended standard library. He gives extension tips for those suppliers who want to provide them.
Most, but not all TR1s were widely implemented in 2005 as part of gcc and MSVC. llvm lib ++ was developed after the TR1 time frame and aimed directly at the new C ++ 11 standard, which moves many TR1 components to the std
and makes them normative (required by the standard).
Clang is known to be used with both llvm lib ++ and gcc libstd ++.
I don't know which std :: lib implementations you need to port. If all the places you need for the port to implement TR1 are safe, otherwise it is not. But TR1 is not a regulatory standard. C ++ 98, C ++ 03 and C ++ 11 are normative standards.
Tested just for fun, and it turns out that libcxx used in Emscripten is a problem, not Clang 3.2.
I trained many, many project owners on how to make my own code that uses TR1 portable through libstdC ++ (has TR1) and libC ++ (has C ++ 11). libC ++ places those TR1 components that were standardized in C ++ 11 in the std
, as specified in C ++ 11. It does this even when -std = C ++ 03. This was done as a transient help. libC ++ does not attempt to be compatible with the C ++ 03 library. Life begins with C ++ 11.
libC ++ has a version number macro called _LIBCPP_VERSION
. If this macro is defined after include'ing std-header, you use lib ++, otherwise you will not do it. Therefore, you can write code like this:
#ifdef _LIBCPP_VERSION // using libc++ #include <memory> typedef std::shared_ptr<MyType> MyTypePtr; #else // !_LIBCPP_VERSION // not using libc++ #include <tr1/memory> typedef std::tr1::shared_ptr<MyType> MyTypePtr; #endif // _LIBCPP_VERSION
Note that you must first include some kind of std header for _LIBCPP_VERSION
to determine whether or not it. If you need to include the std header for free to find out if _LIBCPP_VERSION
is _LIBCPP_VERSION
, use:
#include <ciso646> // detect std-lib
C ++ 98/03/11 specify <ciso646>
to not do anything. So it is very cheap. The libC ++ implementation of this header does nothing but define _LIBCPP_VERSION
.
After that, your code can now easily switch between libC ++ and other libraries that implement TR1.