[llvm] DenseMap: support enum class keys (PR #95972)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 18 12:18:20 PDT 2024
================
@@ -297,6 +297,27 @@ template <typename... Ts> struct DenseMapInfo<std::tuple<Ts...>> {
}
};
+// Provide DenseMapInfo for enum classes.
+template <typename Enum>
+struct DenseMapInfo<Enum, std::enable_if_t<std::is_enum_v<Enum>>> {
+ using UnderlyingType = std::underlying_type_t<Enum>;
+ using Info = DenseMapInfo<UnderlyingType>;
+
+ static Enum getEmptyKey() { return static_cast<Enum>(Info::getEmptyKey()); }
+
+ static Enum getTombstoneKey() {
+ return static_cast<Enum>(Info::getTombstoneKey());
+ }
+
+ static unsigned getHashValue(const Enum &Val) {
+ return Info::getHashValue(static_cast<UnderlyingType>(Val));
+ }
+
+ static bool isEqual(const Enum &LHS, const Enum &RHS) {
+ return Info::isEqual(static_cast<UnderlyingType>(LHS),
+ static_cast<UnderlyingType>(RHS));
----------------
nikic wrote:
Could directly compare `LHS == RHS` here?
https://github.com/llvm/llvm-project/pull/95972
More information about the llvm-commits
mailing list