C++ language version detection

One of those snippets you just copy-paste. Can I please explain a few basics before the next copy-paste?

ISO C++ committee WG21 document N4835 is C++20 draft. Please look it up.

__cplusplus macro in C++20 draft, 2019 Dec

201703L is in there to indicate C++20 value is not declared and defined yet. That 201703L, is standard C++17 value. Each and every compiler vendor declares 201703L for C++17 for __cplusplus. (Not so, yet for the C++20 code.)

These macros are for:

  • situations when customers **might** try your app in systems or situations, which are undeclared as your app operating requirements.
  • situation when your code uses C++20 or 23 in the future
  • Etc.

One could indeed simplify.

That would indeed cover the operational requirements of the C++ compiler and language requirements.

Alas, that does not work right now for developers using  Microsoft CL (c++ compiler) . So I had to change it

This is because , for me here __cplusplus == 199711L, and my compiler is

Which is the very latest.

Using CL you need to compile with the /Zc:__cplusplus switch to see the C++ standard defined value of the __cplusplus macro.  But nobody does that.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.