The value for C++20 is 202002L
, as you can see at [cpp.predefined]p1.1:
__cplusplus
The integer literal
202002L
. [ Note: It is intended that future versions of this International Standard will replace the value of this macro with a greater value. — end note ]
Therefore, for compilers that already implement the new standard, you can check by:
#if __cplusplus >= 202002L
// C++20 (and later) code
#endif
This is the compiler support so far:
- Clang >= 10
- GCC >= 11
- MSVC >= 19.29 (requires
/Zc:__cplusplus
) - ICX >= 2021
- ICC: No (version >= 2021 defines
202000L
; notice the0
)