From the Bjarne Stroustrup C ++ 0x FAQ :
__cplusplus
In C ++ 0x, the __cplusplus macro will be set to a value that differs from (more) the current 199711L .
Although it is not as useful as we would like. gcc (apparently for almost 10 years) this value was set to 1 , excluding one main compiler, until it was fixed when gcc 4.7.0 appeared .
These are C ++ standards and what value you should expect in __cplusplus :
- C ++ pre-C ++ 98:
__cplusplus is 1 . - C ++ 98:
__cplusplus is 199711L . - C ++ 98 + TR1: This reads like C ++ 98, and there is no way to check what I know.
- C ++ 11:
__cplusplus is 201103L . - C ++ 14:
__cplusplus is 201402L . - C ++ 17:
__cplusplus is 201703L .
If the compiler may be older than gcc , we need to refer to the specific hacking of the compiler (look at the macro version, compare it with the table with the implemented functions) or use Boost.Config (which provides the corresponding macros ). The advantage of this is that we can really choose the specific functions of the new standard and write a workaround if this function is missing. This is often preferable for a bulk solution, as some compilers will require the implementation of C ++ 11, but offer only a set of functions.
The Stdcxx Wiki hosts a comprehensive matrix to support the C ++ 0x function compiler (if you decide to test the functions themselves).
Unfortunately, a finer-grained check of functions (for example, individual library functions, such as std::copy_if ) can only be performed in the build system of your application (run the code using the function, check if it is compiled and get the correct results - autoconf is the tool of choice if you take this route).
pmr Aug 20 '11 at 2:59 a.m. 2011-08-20 14:59
source share