File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -320,6 +320,35 @@ struct DenseMapInfo<Enum, std::enable_if_t<std::is_enum_v<Enum>>> {
320320
321321 static bool isEqual (const Enum &LHS, const Enum &RHS) { return LHS == RHS; }
322322};
323+
324+ template <typename T>
325+ struct DenseMapInfo <std::optional<T>> {
326+ using Optional = std::optional<T>;
327+ using Info = DenseMapInfo<T>;
328+
329+ static inline Optional getEmptyKey () {
330+ return std::make_optional (Info::getEmptyKey ());
331+ }
332+
333+ static inline Optional getTombstoneKey () {
334+ return std::make_optional (Info::getTombstoneKey ());
335+ }
336+
337+ static unsigned getHashValue (const Optional &OptionalVal) {
338+ return detail::combineHashValue (
339+ OptionalVal.has_value (),
340+ Info::getHashValue (OptionalVal.value_or (Info::getEmptyKey ())));
341+ }
342+
343+ static bool isEqual (const Optional &LHS, const Optional &RHS) {
344+ if (LHS.has_value () && RHS.has_value ()) {
345+ return Info::isEqual (LHS.value (), RHS.value ());
346+ } else if (!LHS.has_value () && !RHS.has_value ()) {
347+ return true ;
348+ }
349+ return false ;
350+ }
351+ };
323352} // end namespace llvm
324353
325354#endif // LLVM_ADT_DENSEMAPINFO_H
You can’t perform that action at this time.
0 commit comments