Reputation: 24850
Are there any predefined macros for C++ in order the code could identify the standard?
e.g. Currently most compilers puts "array" into "tr1" folder but for C++11 it would be part of STL. So currently
#include <tr1/array>
but c++11
#include <array>
What is the predefined macros for 03 standard and 11 standard in order I can use #ifdef
to identify?
Also, I suppose there are macros for C90 and C99?
Thanksx
Upvotes: 24
Views: 15741
Reputation: 473926
Ultimately, you're going to have to use compiler-specific information. At least, until C++0x becomes more widespreadly implemented. You basically need to pick driver versions that implement something and test compiler-specific macros on them.
The Boost.Config library has a number of macros that can help you.
Upvotes: 1
Reputation: 30035
In C++11 the macro
__cplusplus
will be set to a value that differs from (is greater than) the current199711L
.
You can likely test it's value to determine if it's c++0x or not then.
Upvotes: 20
Reputation: 39099
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.
Upvotes: 7
Reputation: 299979
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 thatstd::tr1::array
is defined in<tr1/array>
instead of the default<array>
.
And you're done.
Upvotes: 7