Some C++ feature test macros( e.g. __cpp_lib_three_way_comparison
) require header inclusion(e.g. <compare>
) to test for them.
This seems very backwards, e.g. maybe I want to include header only when I know it is supported by compiler(more precisely compiler+std lib impl it uses), e.g. let's say I have my_fancy_string_view
and I want to typedef it to std::string_view
if std::string_view
is available, but to detect if std::string_view
is available I need to include <string_view>
...
Is this just a "bug/oopsie" in design of this feature, or is there a good reason why all feature test macros are not predefined by compiler? My guess is to maybe allow the mixing of STL implementations, e.g. clang on some platforms uses gcc's std lib implementation, but then again I presume compilers know what std lib implementations they use so they can adjust predefined macros.
I know <version>
header exists, but that does not help me since it was added only in C++20.
It may be nice in 10+ years when my baseline is C++20, but for now it is not that useful.
Also fact that this header was added might suggest that in fact requiring "heavy" includes was a mistake, but I would like to get the expert opinion on this.
P.S. This is proposal that added <version>
, but it is very tiny so no details...