gpt4 book ai didi

c++ - 哪些平台不在 type_info op== 中使用字符串比较?

转载 作者:IT老高 更新时间:2023-10-28 23:02:38 24 4
gpt4 key购买 nike

这是type_info::operator==的典型实现:

#if _PLATFORM_SUPPORTS_UNIQUE_TYPEINFO
bool operator==(const type_info& __rhs) const {
return __mangled_name == __rhs.__mangled_name;
}
#else
bool operator==(const type_info& __rhs) const {
return __mangled_name == __rhs.__mangled_name ||
strcmp(__mangled_name, __rhs.__mangled_name) == 0;
}
#endif

在 libstdc++ 中,它由 __GXX_MERGED_TYPEINFO_NAMES 控制,
在 libc++ 中是 _LIBCPP_NONUNIQUE_RTTI_BIT,
MSVC 总是比较字符串。

不比较字符串的平台有哪些?

最佳答案

In libstdc++ it's controlled with __GXX_MERGED_TYPEINFO_NAMES

In newer versions of gcc (since 23 Jul 2009) this macro is set to 0 by default .它总是首先比较指针,如果失败,它们会进行完整的字符串比较。 See here :

We used to do inline pointer comparison by default if weak symbols are available, but even with weak symbols sometimes names are not merged when objects are loaded with RTLD_LOCAL, so now we always use strcmp by default.

关于c++ - 哪些平台不在 type_info op== 中使用字符串比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49773686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com