检查C ++ 11库功能 [英] Checking for C++11 library features

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

问题描述

什么是检查标准库的特定C ++ 11功能的好方法。

What is a good way of checking for the presence of specific C++11 features of the standard library.

对于编译器功能我只是顺便检查编译器版本的(IMHO)主要编译器( VC ++ gcc clang )虽然这不是最好和最灵活的方法,但我不知道什么更好,除了 clang ,它有非常好的 __ has_feature 宏。

For compiler features I just went by the way of checking the compiler version for the (IMHO) major compilers (VC++, gcc, clang at the moment, maybe Intel) Although this is not the best and most flexible approach, I don't know of anything better yet, except for clang which has the really nice __has_feature macros.

但是更糟糕的是库功能,它们没有严格地耦合到编译器。目前我想使用相同的方法检查编译器版本为 VC ++ (这是很容易,假设它使用自己的库)。对于 clang ,我可以至少使用 __ has_include 来进行大规模的基于头的查询。除此之外,我想如果定义检查 __ GLIBCXX __ 的值可能是一个好主意,但是我再也找不到任何具体的信息 libstdc ++ 版本引入了除了当前版本支持的功能之外的其他功能。

But it's even worse for library features, which are not coupled that rigidly to the compiler. At the moment I want to use the same approach of checking the compiler version for VC++ (where it's pretty easy, assuming it uses its own library). For clang I can at least use __has_include for large-scale header-based queries. Other than that I guess checking __GLIBCXX__'s value if defined might be a good idea, but then again I cannot find any information of what specific libstdc++ versions introduced which features, other than what the current version supports.

这些方法应该保留预处理器检查等,因为我想在头文件中使用它,只有库没有任何复杂的配置过程,并且没有使用任何第三方库(是的, boost 是第三方)。

The methods should be kept to preprocessor checks and the like, since I want to use it in a header-only library without any sophisiticated configure procedure and without using any third-party libraries (and yes, boost is third-party).


  1. 那么我在这些(很窄的)条件下检查特定C ++ 11库特性的可能性是什么。

  1. So what are my possibilities of checking for specific C++11 library features under those (pretty narrow) conditions. Maybe even on the scale of particular functions or types being declared?

如果检查编译器或库版本仍然是最好的方法,我在哪里可以找到详细的有关特定版本的 libstdc ++ (以及其他重要的版本, libc ++ )可能支持的特定C ++ 11功能的信息? p>

If checking for the compiler or library version is still the best approach, where can I find detailed information about the particular C++11 features supported by a specific version of libstdc++ (and maybe other important ones, libc++ perhaps)?

FWIW目前在< cstdint> ,C ++ 11 < cmath> 函数和 std :: hash ,但这可能会更改,

FWIW at the moment I'm interrested in <cstdint>, C++11 <cmath> functions and std::hash, but this may change and is probably not of importance for the general approach.

推荐答案

除了知道哪个版本实现了哪个编译器之外,这里真的没有什么好办法什么和有适当的定义到位。

There is really nothing nice you can do here besides knowing which compiler in which version implements what and have the proper defines in place.

gcc拥有特殊表用于库功能。 __ has_include 的主要问题当然是添加到包含在old中的标准。 libstdc ++ 也有必要的include,但这并不意味着必须定义启用这些文件的内容。它也不会告诉你任何实际的可用实现的金额(有时是不完整的)。

gcc has a special table for library functionality. The main problem of __has_include are of course additions to the standard that live in old includes. libstdc++ also has the necessary includes, but that doesn't mean the necessary define to enable the content of those files. It also wont tell you anything about the actual amount of available implementation (which sometimes is incomplete).

由于你有一个标题库,这不适用于你,但仍然很重要:C ++ 11和C ++ 03之间的二进制不兼容性可能会回来,并咬你。

As you have a header-only library this doesn't apply to you, but is still important: binary incompatibility between C++11 and C++03 can come back and bite you.

我真的不会接近任何而是使用 Boost.Config 。最初它只描述语言功能,但现在已扩展到标准库头文件。

I seriously wouldn't approach any of that on my own and rather use Boost.Config. Originally it only described language features but has now expanded to standard library headers.

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

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