我想在我的程序中使用一些 C++11 功能。将来我可能不得不与其他人分享我的源代码。 如何在代码中断言应该使用 C++11 来编译我的程序? 较旧的编译器可能会抛出错误,但我希望清楚地告知用户 C++ 11 是必需的。
如果重要的话,我正在使用以下 C++11 功能:
- 指定存储大小的枚举
- 标准共享指针
谢谢
最佳答案
您可以检查 __cplusplus
宏的值是否为 201103L
或更大:
#if __cplusplus < 201103L
#error This code requires C++11
#endif
C++11 16.8 预定义的宏名称:
The following macro names shall be defined by the implementation:
__cplusplus
The name
__cplusplus
is defined to the value201103L
when compiling a C++ translation unit. (155)(155) It is intended that future versions of this standard will replace the value of this macro with a greater value. Non-conforming compilers should use a value with at most five decimal digits.
关于c++ - 如何断言应该使用 C++11 来编译我的程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15997869/