问题描述
我编写一些C ++ 11代码,假设有关 std :: string
的属性是有效的,但表示在C + +11。在早些时候,libstdc ++的 basic_string
实现符合98/03的要求,但不符合更严格的C ++ 11要求。
根据我的理解,libstdc ++修复了 basic_string
的问题。问题是有很多版本的库,人们使用它不实现这个修复。我的代码可能会以许多不愉快的方式默默地失败。
我想有一个 static_assert
用户试图编译我的库对那些不相容的版本的libstdc ++。如何检测版本,同样重要的是,我应该查找哪个版本?
std :: string
引入了新的(双)ABI在GCC 5(
宏 _GLIBCXX_USE_CXX11_ABI
旧的或新的ABI正在使用,因此只需检查:
#if _GLIBCXX_USE_CXX11_ABI
当然只有libstdc ++。
I'm writing some C++11 code that makes assumptions about the nature of
std::string
that are valid, but represent behavior that was changed in C++11. In the earlier days, libstdc++'sbasic_string
implementation conformed to the 98/03 requirements, but not to the more strict C++11 requirements.As I understand it, libstdc++ has fixed the issues around
basic_string
. The problem is that there are many versions of the library that people use which do not implement this fix. And my code may silently fail in many unpleasant ways on them.I would like to have a
static_assert
fire if the user attempts to compile my library against those non-conformant versions of libstdc++. How do I detect the version, and equally importantly, which version should I look for?解决方案The new C++11 compliant
std::string
was introduced with the new (dual) ABI in GCC 5 (Runtime Library Section of the changelog).The macro
_GLIBCXX_USE_CXX11_ABI
decides whether the old or new ABI is being used, so just check it:#if _GLIBCXX_USE_CXX11_ABI
Of course that's specific to libstdc++ only.
这篇关于测试libstdc ++的版本是否使用符合C ++ 11的std :: string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!