更新时间:2023-11-10 08:40:16
这基本上是。然后将其作为第三个模板参数提供给 unordered_map
类型(我假设它是C ++ 0x)。我将其概括为它可以在任何情况下使用,而不是只是 string
:
That's basically it. You then provide it as the third template parameter to the unordered_map
type (Which I will assume to be the C++0x one). I would generalize it so it's usable in any situation, rather than just string
:
struct dereference_hash
{
template <typename T>
std::size_t operator()(const T* pX)
{
return std::hash<T>()(*pX);
}
};
typedef std::unordered_map<std::string*, int, dereference_hash> map_type;