GNU C++ 如何检查 -std=c++0x 何时生效?

2021-12-18 00:00:00 gcc g++ c++ c++11

我的系统编译器 (gcc42) 与我想要的 TR1 功能配合得很好,但尝试支持系统以外的较新编译器版本,尝试访问 TR1 标头时出现 #error 要求 -std=c++0x 选项,因为了解它如何与图书馆或类似的一些集线器连接.

My system compiler (gcc42) works fine with the TR1 features that I want, but trying to support newer compiler versions other than the systems, trying to accessing TR1 headers an #error demanding the -std=c++0x option because of how it interfaces with library or some hub bub like that.

/usr/local/lib/gcc45/include/c++/bits/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.

必须提供一个额外的开关是没有问题的,在这个系统(FreeBSD)下支持GCC 4.4和4.5,但显然它改变了画面!

Having to supply an extra switch is no problem, to support GCC 4.4 and 4.5 under this system (FreeBSD), but obviously it changes the picture!

使用我的系统编译器(g++ 4.2 默认方言):

Using my system compiler (g++ 4.2 default dialect):

#include <tr1/foo>
using std::tr1::foo;

通过 -std=c++0x 使用更新 (4.5) 版本的编译器:

Using newer (4.5) versions of the compiler with -std=c++0x:

#include <foo>
using std::foo;

无论如何使用预处理器,我可以判断 g++ 是否在启用 C++0x 功能的情况下运行?

Is there anyway using the pre processor, that I can tell if g++ is running with C++0x features enabled?

我正在寻找这样的东西:

#ifdef __CXX0X_MODE__
#endif

但我没有在手册或网上找到任何内容.

but I have not found anything in the manual or off the web.

以这种速度,我开始认为生活会更轻松,使用 Boost 作为依赖项,而不用担心在 TR4 之前出现新的语言标准......呵呵.

At this rate, I'm starting to think that life would just be easier, to use Boost as a dependency, and not worry about a new language standard arriving before TR4... hehe.

推荐答案

如果你用 -std=c++0x 编译,那么 __GXX_EXPERIMENTAL_CXX0X__ 将被定义.

If you compile with -std=c++0x, then __GXX_EXPERIMENTAL_CXX0X__ will be defined.

相关文章