How do you determine what version of the C++ standard is implemented by your compiler? As far as I know, below are the standards I've known:
- C++03
- C++98
How do you determine what version of the C++ standard is implemented by your compiler? As far as I know, below are the standards I've known:
From the Bjarne Stroustrup C++0x FAQ:
Although this isn't as helpful as one would like.
gcc
(apparently for nearly 10 years) had this value set to1
, ruling out one major compiler, until it was fixed when gcc 4.7.0 came out.These are the C++ standards and what value you should be able to expect in
__cplusplus
:__cplusplus
is1
.__cplusplus
is199711L
.__cplusplus
is201103L
.__cplusplus
is201402L
.__cplusplus
is201703L
.If the compiler might be an older
gcc
, we need to resort to compiler specific hackery (look at a version macro, compare it to a table with implemented features) or use Boost.Config (which provides relevant macros). The advantage of this is that we actually can pick specific features of the new standard, and write a workaround if the feature is missing. This is often preferred over a wholesale solution, as some compilers will claim to implement C++11, but only offer a subset of the features.The Stdcxx Wiki hosts a comprehensive matrix for compiler support of C++0x features (if you dare to check for the features yourself).
Unfortunately, more finely-grained checking for features (e.g. individual library functions like
std::copy_if
) can only be done in the build system of your application (run code with the feature, check if it compiled and produced correct results -autoconf
is the tool of choice if taking this route).By my knowledge there is no overall way to do this. If you look at the headers of cross platform/multiple compiler supporting libraries you'll always find a lot of defines that use compiler specific constructs to determine such things:
You probably will have to do such defines yourself for all compilers you use.
Depending on what you want to achieve, Boost.Config might help you. It does not provide detection of the standard-version, but it provides macros that let you check for support of specific language/compiler-features.
Please, run the following code to check the version.
After a quick google:
__STDC__
and__STDC_VERSION__
, see hereC++0x FAQ by BS