[llvm] DenseMapInfo: support std::optional<T> (PR #147851)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 9 17:57:05 PDT 2025


================
@@ -320,6 +321,32 @@ struct DenseMapInfo<Enum, std::enable_if_t<std::is_enum_v<Enum>>> {
 
   static bool isEqual(const Enum &LHS, const Enum &RHS) { return LHS == RHS; }
 };
+
+template <typename T> struct DenseMapInfo<std::optional<T>> {
+  using Optional = std::optional<T>;
+  using Info = DenseMapInfo<T>;
+
+  static inline Optional getEmptyKey() {
+    return std::make_optional(Info::getEmptyKey());
----------------
kuhar wrote:

Do we need to use `make_optional` here? I'd think a simple `return {foo};` or `return Optional{foo};` should work. Also below.

https://github.com/llvm/llvm-project/pull/147851


More information about the llvm-commits mailing list