Reputation: 1
is there a way to use like:
#if (VERSION_C < 20) //where version_c is the version of C++ the compiler is using
#use FUNCTION1
#elseif use FUNCTION2
I want to use C++20 fmt()
and I understand that I can just use an older way of doing it, but since I am learning to program, I am curious if this is even possible so that a program's source code could be written once and use the most modern features available to the local compile environment...It will compile on my system but it will not compile on another system unless they use the most current preview version,
Thanks for the help guys! (This is my very first question on here)
Upvotes: 0
Views: 440
Reputation: 96831
There's the __cplusplus
macro which expands to the date when the current standard was released.
But it's mostly useless, since compilers don't implement all features from a new standard at the same time.
Because of that we have a bunch of separate feature test macros. The one you're looking for is __cpp_lib_format
.
It was added in C++20, then its value was changed in C++23 to indicate new improvements to std::format
.
But if you want my opinion, forget about std::format
for now.
Use libfmt, which works on all major compilers, and has more features.
Upvotes: 2