10

我想在编译时根据其派生类型为类生成哈希。今天我像这样生成它:

template<class Type>
class TypeBase 
{
public:
    static const unsigned s_kID;
};

template<class Type>
const unsigned TypeBase<Type>::s_kID = hash(typeid(Type));

但这会生成(非常不必要的)运行时初始化代码( hash(..) 函数基于 std::type_info::name() 进行简单的哈希)

想法?

4

1 回答 1

3

考虑到进程启动时发生的所有其他事情,以及现有代码的简单和优雅,假设您没有散列大量类型,我会完全保留现有解决方案。

于 2011-08-22T14:22:24.333 回答