C ++ 11功能的可用性 [英] Availability of C++11 features

查看:130
本文介绍了C ++ 11功能的可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译器供应商一直采用C ++ 11特性,这是可预测的,因为它们中的许多不容易实现。

Compiler vendors have been adopting C++11 features piecemeal, which was predictable, as many of them are not easily implemented.

编译器完全支持的规范的标准方式是通过 __ cplusplus 预定义宏。然而,主要供应商报告 __ cplusplus = 199711L,意味着他们只完全支持C ++ 98(例如MSVC14)。这个(可能)意味着他们不完全支持C ++ 11规范,即使他们可能已经实现了大部分的功能。

The standard way for reporting which spec the compiler fully supports is via the __cplusplus predefined macro. However, major vendors are reporting __cplusplus = 199711L, meaning they are only fully supporting C++98 (eg. MSVC14). This (presumably) means that they do not fully support the C++11 spec, even though they may have implemented a lion's share of the functionality.

我想开始使用C ++ 11的功能,当它们可用(和回退到现有的代码,当他们不是)。但是,我的代码必须支持许多编译器,包括我可能无法使用的专有编译器。有没有什么标准的方法来知道哪些C ++ 11功能可以从编译器,而不知道具体使用哪个编译器? (如果编译器以非标准方式运行,那么检测行为是不正确的)。

I would like to start using C++11 features, when they are available (and fallback to existing code when they are not). However, my code must support many compilers, including proprietary compilers which I may not have access to use. Is there any standard way to know which C++11 features are available from a compiler, without knowing specifically which compiler is being used? (if a compiler behaves in a non-standard way, then it is acceptable for the detection behavior to be incorrect).

注意:这个问题是我的问题的一个概括' static_assert c ++ 11 的可用性,这是不是很受欢迎,因为

NOTE: This question is a generalization of my question 'Availability of static_assert c++11', which was not very well received, because I think my motivation was misunderstood.

推荐答案

您可能对 功能测试宏 ,可让您测试对于特定的C ++ 11,C ++ 14或甚至C ++ 17特性,例如 __ cpp_static_assert __ cpp_lib_make_unique __ cpp_variable_templates 。 Clang和GCC已支持此功能,请参阅 现场演示

You might be interested in feature test macros, which enable you to test for specific C++11, C++14 or even C++17 features, such as __cpp_static_assert, __cpp_lib_make_unique or __cpp_variable_templates. Clang and GCC already support this, see a live demo.

这篇关于C ++ 11功能的可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆