简体   繁体   English

C ++ 11功能检查

[英]C++11 feature checking

How do I check for presence of individual C++0x/C++11 language features? 如何检查单个C ++ 0x / C ++ 11语言功能的存在? I know Clang has a nice system for this. 我知道Clang为此提供了一个不错的系统。 What about GCC, Visual Studio or Boost? GCC,Visual Studio或Boost呢? I guess one way to do it is to detect the compiler version and relate that to the features introduced in that version. 我想做到这一点的一种方法是检测编译器版本并将其与该版本中引入的功能相关联。 But that is cumbersome. 但这很麻烦。 Has someone already done that? 有人已经这样做了吗?

boost config comes with a script to check for some but not all C++11 features. boost config带有一个脚本,用于检查某些但不是全部的C ++ 11功能。

It generates a config-file with macros for each feature. 它为每个功能生成带有宏的配置文件。

Your build-tool may be able to help with this. 您的构建工具也许可以帮助您。

CMake has the try_compile command which allows you to test whether a code sample will compile and set a variable based on the result of compilation. CMake具有try_compile命令,该命令可让您测试代码示例是否将编译并根据编译结果设置变量。

At the moment I've just been using the more commonly supported features such as auto typing. 目前,我一直在使用更常用的功能,例如auto键入。

You can often use Boost to replace the missing library features, and this may be the best option for a few year while compilers and libraries are updated and bugs fixed. 您通常可以使用Boost来替换缺少的库功能,并且这可能是几年来更新编译器和库并修复错误时的最佳选择。

The C++11 feature compatibility list for GCC is here: http://gcc.gnu.org/projects/cxx0x.html GCC的C ++ 11功能兼容性列表在此处: http : //gcc.gnu.org/projects/cxx0x.html

Note the warning: 注意警告:

Important: GCC's support for C++11 is still experimental. 重要提示:GCC对C ++ 11的支持仍处于试验阶段。 Some features were implemented based on early proposals, and no attempt will be made to maintain backward compatibility when they are updated to match the final C++11 standard. 有些功能是根据早期建议实施的,并且在更新它们以符合最终的C ++ 11标准时,不会尝试保持向后兼容性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM