Created
January 14, 2021 10:07
-
-
Save treastrain/483a2d233560dc99fda8e59b6fd03361 to your computer and use it in GitHub Desktop.
コンパイラ・C++ 標準の判定
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 <iostream> | |
int main(int, char**) { | |
#if __cplusplus > 199711L | |
system("uname -a"); | |
#endif | |
// コンパイラの判定 | |
#ifdef __clang_version__ | |
std::cout << "Compiled by Clang " << __clang_version__ << std::endl; | |
#elif defined __GNUC__ | |
std::cout << "Compiled by GCC " << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << std::endl; | |
#elif defined _MSC_VER | |
std::cout << "Compiled by Microsoft Visual C++ (MSVC) " << _MSC_VER << "(" << _MSC_FULL_VER << ")" << std::endl; | |
#else | |
std::cout << "Compiled by unknown compiler" << std::endl; | |
#endif | |
// C++ 標準の判定 | |
#if __cplusplus == 199711L | |
std::cout << "C++98 or C++03, 'ISO C++ 1998 with amendments' standard"; | |
#elif __cplusplus == 201103L | |
std::cout << "C++11, 'ISO C++ 2011 with amendments' standard"; | |
#elif __cplusplus == 201402L | |
std::cout << "C++14, 'ISO C++ 2014 with amendments' standard"; | |
#elif __cplusplus == 201703L | |
std::cout << "C++17, 'ISO C++ 2017 with amendments' standard"; | |
#elif __cplusplus == 201707L | |
std::cout << "C++2a, 'Working draft for ISO C++ 2020' standard"; | |
#elif __cplusplus == 201709L | |
std::cout << "C++2a, 'Working draft for ISO C++ 2020' standard"; | |
#elif __cplusplus == 202002L | |
std::cout << "C++20, 'ISO C++ 2020 with amendments' standard"; | |
#else | |
std::cout << "C++??"; | |
#endif | |
std::cout << " (__cplusplus: " << __cplusplus << ")" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment