'What do the values of the C++ "feature test macros" mean?
To test for a feature, cppreference mentions these feature test macros: link.
If the feature is present in the compiler, the macro is defined. But I don't understand why, if defined, they are defined to something like 201606
, which I believe is a version of C++, not of the compiler.
For example, I am using a very recent version of GCC with -std=c++17
for the feature __cpp_lib_hardware_interference_size
. The macro is undefined, which I take to mean GCC doesn't have the feature, despite trying 8.2.1 with the c++17 (and c++2a) switch. In this case, what is the significance of the documented value:
__cpp_lib_hardware_interference_size 201703
(inside the cppreference link)?
Solution 1:[1]
Based on cppreference.com, it says:
The following macros expand to a numeric value corresponding to the year and month when the feature has been included in the working draft.
When a feature changes significantly, the macro will be updated accordingly.
So, you can check if the feature exists checking if the macro is defined. Or you can check for the feature version based on the macro value.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | J. Calleja |