编译时的c++类型id
C++ type id at compile time
我想在编译时根据类的派生类型生成一个哈希值。今天我像这样生成它:
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()进行简单的散列)
想法?
考虑到进程启动时发生的所有其他事情,以及您现有的代码是多么简单和优雅,假设您不散列大量类型,我将保留您现有的解决方案。
相关文章:
- 使用类型id运算符的最佳替代方法
- 类型ID,如何仅获取类型名称
- 自动初始值设定项类型ID 信息
- 类型ID指针和引用比较差异?
- gcc 发出了与解析新表达式中的类型 ID 相关的错误
- 我可以从静态基方法获取当前类类型 ID 吗?
- 关于C++中的类型id函数
- reinterpret_cast<类型ID>"type-id"可以是变量吗?
- 我想看到一个在整个后缀表达式的上下文中查找转换类型 id 的示例
- 每种类型的编译时类型ID
- C++模板和类型 ID
- C++类型比较:类型 ID 与双重调度dynamic_cast
- 编译时生成的常量类型 ID
- 类型id(T) 是在运行时还是在编译时被计算
- 如何在编译时生成密集的唯一类型ID
- 类型ID 和type_info类
- 函数未在类型id中调用
- 多态指针的类型id
- 类型id结果不匹配
- 类型ID的成本是多少?