You can just specialise std::hash
for your type:
namespace std {
template <>
struct hash<FullyQualified::LibEnum> {
size_t operator ()(FullyQualified::LibEnum value) const {
return static_cast<size_t>(value);
}
};
}
Alternatively, you can define a hash
type where ever you like and just provide it as the additional template argument when instantiating std::unordered_map<FooEnum>
:
// Anywhere in your code prior to usage:
struct myhash {
std::size_t operator ()(LibEnum value) const {
return static_cast<std::size_t>(value);
}
};
// Usage:
std::unordered_map<LibEnum, T, myhash> some_hash;
Neither methods require you to modify the library.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…