我需要为运行时相等性比较的类型分配唯一值。使用函数指针作为值来完成工作:
#include <cassert>
struct type_id {
using value_type = void(*)();
template<class T>
static void get() { }
};
// some types
struct A {};
struct B {};
int main() {
type_id::value_type a = &type_id::get<A>;
type_id::value_type b = &type_id::get<B>;
assert(a != b);
return 0;
}
我的问题如下:我应该注意哪些限制(如果有的话)?我对多个翻译单元的独特性和表现特别好奇。