How do I check for C++20 support? What is the value of __cplusplus for C++20? [duplicate]

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 the 0)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)