Last active
August 29, 2022 16:26
-
-
Save gunchev/207d0d74f43fd31b3593e14b4200c32c to your computer and use it in GitHub Desktop.
Using C++ preprocessor to detect C++ standard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
int main() { | |
// Also see https://en.cppreference.com/w/cpp/feature_test | |
// and https://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros | |
#ifndef __cplusplus | |
#error C++ is required | |
#elif __cplusplus < 199711L | |
puts("before C++98?!?"); | |
#elif __cplusplus < 201103L | |
puts("C++98"); | |
#elif __cplusplus < 201402L | |
puts("C++11"); | |
#elif __cplusplus < 201703L | |
puts("C++17"); | |
#elif __cplusplus < 202002L | |
puts("C++17"); | |
#elif __cplusplus < 202100L | |
puts("C++20"); | |
#else | |
puts("C++23 or newer"); | |
#endif | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment