可能性の重複のための任意のtypeidの最適化:私は
&operand->type() == &typeid(ValueType)
に以下operand->type() == typeid(ValueType)
行を変更した場合、コードはまだgccで動作し、かかる
When can typeid return different type_info instances for same type?ブースト:: 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