可能重复任何typeid的优化:
When can typeid return different type_info instances for same type?的boost ::对C++ 11
如果我改变以下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;
}
这在技术上是一个C++ 03的问题,而这个是C++ 11。编辑,使其明确不是重复(答案仍然是正确的) – MSalters 2012-04-12 10:38:01