Related to questions How do I check for C++11 support? and What is the value of __cplusplus for C++17?
How can I inquire whether the compiler can handle / is set up to use C++20? I know that it is, in principle, possible to inquire the C++ version by:
#if __cplusplus > ??? // C++20 code here #endif
What should ???
be for C++20?
You just have to manually enter c++20 to setting C++ Language Dialect . Visual Studio 2019 (latest version 16.10, on Windows) is the only IDE currently coming with a compiler that fully supports C++20.
C++17 Support in GCC C++17 features are available since GCC 5. This mode is the default in GCC 11; it can be explicitly selected with the -std=c++17 command-line flag, or -std=gnu++17 to enable GNU extensions as well.
To see if your compiler has C++11 support, run it with just the --version option to get a print out of the version number. Do this for whichever compiler(s) you wish to use with Rosetta. Acceptable versions: GCC/g++: Version 4.8 or later.
C++20 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++20 replaced the prior version of the C++ standard, called C++17. The standard was technically finalized by WG21 at the meeting in Prague in February 2020, approved on 4 September 2020, and published in December 2020.
It's too early for that.
Until the standard replaces it, use:
#if __cplusplus > 201703L // C++20 code #endif
since the predefined macro of C++20 is going to be larger than the one of C++17.
As @SombreroChicken's answer mentions, [cpp.predefined] (1.1) specifies (emphasis mine):
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value of this macro with a greater value.]
The macros used, as of Nov 2018, are:
201709L
for C++2a. Live demo 201707L
. Live demo 201704L
(as @Acorn's answer mentions).PS: If you are interested in specific features, then [cpp.predefined] (1.8) defines corresponding macros, which you could use. Notice though, that they might change in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With