C++17 language version detection

One of those snippets you just copy-paste. Can I please explain to you a few basics before your copy-paste this one?

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.
    • you have you app operating requirements, yes?
  • situation, when your code needs to know, is it in the C++20 or C++23 mode, in the future
  • Etc.

One could indeed simplify and fix on C++17

Instead of a page long “wall of macros” that decides which C++ version is on, one can get hold of only the C++17 value. This is all we might need, are we bellow required C++ 17 value or are we above the required mark.

This is the way to demand exactly C++17 and nothing else. And that will work “forever”.

That would indeed cover the operational requirements of the C++17 language requirement.

cl.exe has to be the odd one out

Alas, that does not work right now for developers using  Microsoft cl.exe (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.

And what we do when C++20 becomes official?

At that moment  __cplusplus will be having the official value which we will use. Very likely our app operational requirement will then become C++17 or C++20.

And yes, that would be an exercise for the reader.

Administrator of an Legacy farm, at work.