C++11 predefined macro

From Stroustrup's C++11 FAQ

In C++11 the macro __cplusplus will be set to a value that differs from (is greater than) the current 199711L.

You can likely test it's value to determine if it's c++0x or not then.


Nitpick...

Your particular issue does not depend on your compiler, it depends on the Standard Library implementation.

Since you are free to pick a different Standard Library that the one provided by your compiler (for example, trying out libc++ or stlport), no amount of compiler specific information will help you here.

Your best bet is therefore to create a specific header file yourself, in which you will choose either one or the other (depending on a build option).

// array.hpp
#ifdef STD_HAS_TR1_ARRAY_HEADER
#include <tr1/array>
#else
#include <array>
#endif

You then document the compiler option:

Passing -DSTD_HAS_TR1_ARRAY_HEADER will mean that std::tr1::array is defined in <tr1/array> instead of the default <array>.

And you're done.


From the draft N3242:

16.8 Predefined macro names                          [cpp.predefined]
...
   The name _ _ cplusplus is defined to the value 201103L when
   compiling a C++ translation unit. 155)
...
155) It is intended that future versions of this standard will
     replace the value of this macro with a greater value.
     Non-conforming compilers should use a value with at most five 
     decimal digits.

Tags:

C++

C++11