gpt4 book ai didi

c++ - 针对 C++11 的 boost::any typeid 优化

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:31:13 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
When can typeid return different type_info instances for same type?

如果我将下面的 operand->type() == typeid(ValueType) 行更改为 &operand->type() == &typeid(ValueType),则代码仍然适用于 gcc,并且在可执行文件中占用的空间更少(并且多年来一直如此),但是 C++11 标准是否提供任何保证,这种优化应该适用于不同的编译器?

template<typename ValueType>
ValueType * any_cast(any * operand)
{
return operand &&
#ifdef BOOST_AUX_ANY_TYPE_ID_NAME
std::strcmp(operand->type().name(), typeid(ValueType).name()) == 0
#else
operand->type() == typeid(ValueType)
#endif
? &static_cast<any::holder<ValueType> *>(operand->content)->held
: 0;
}

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